Message: Return type of CI_Session_files_driver::open($save_path, $name) should either be compatible with SessionHandlerInterface::open(string $path, string $name): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::close() should either be compatible with SessionHandlerInterface::close(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::read($session_id) should either be compatible with SessionHandlerInterface::read(string $id): string|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::write($session_id, $session_data) should either be compatible with SessionHandlerInterface::write(string $id, string $data): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::destroy($session_id) should either be compatible with SessionHandlerInterface::destroy(string $id): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Message: Return type of CI_Session_files_driver::gc($maxlifetime) should either be compatible with SessionHandlerInterface::gc(int $max_lifetime): int|false, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Use Meaningful, descriptive words to name variables. Do not use abbreviations.
Example
Good
string address;
int salary;
Bad
string nam;
string addr;
int sal;
Avoid using single-character variable names like i, n, s, etc. Expect in the loops. Use names like index, temp.
Example
Avoid using underscores (_) for local variable names.
Use 'is' keyword for boolean functions
private bool _isFinished ();
The prefix for the UI elements should be appropriate so that you can identify them from the rest of the variables. A brief list is given below.
Example
Control
Prefix
Label
lbl
TextBox
txt
DataGrid
dtg
Button
btn
ImageButton
imb
Use Pascal Case for file names.
Indentation and Spacing
Use TAB for indentation. Do not use SPACES. Define the Tab size as 4.
Comments should be on the same level as the code (use the same level of indentation).
Example
Good
// Format a message and display
string myMessage = " C# best practices ";
DateTime currentTime = DateTime.Now;
string infoMessage = myMessage + ", the time is : " + currentTime.ToShortTimeString();
MessageBox.Show( infoMessage );
Bad
// Format a message and display
string myMessage = " C# best practices ";
DateTime currentTime = DateTime.Now;
string infoMessage = myMessage + ", the time is : " + currentTime.ToShortTimeString();
MessageBox.Show ( infoMessage );
The code should be properly formatted.
separate logical groups of code Using one blank line.
Example
Good
bool ShowMessage(string name) {
string fullName = "Hello " + name;
DateTime currentTime = DateTime.Now;
string message = fullName + ", the time is : " + currentTime.ToShortTimeString();
MessageBox.Show(message);
if (...) {
// Write your code here
// ...
return false;
}
return true;
}
Bad
bool ShowMessage(string name) {
string fullName = "Hello " + name;
DateTime currentTime = DateTime.Now;
string message = fullName + ", the time is : " + currentTime.ToShortTimeString();
MessageBox.Show(message);
if (...) { // code here
// ... return false;
}
return true;
}
Format the code using curly braces and separate the method with new line.
Example
Good
if ( ... )
{
// write your code here
}
Bad
if ( ... ) {
// Write your code here }
Always use a single space before and after operators and braces.
Example
Good
if(showResult)
{
for ( int j = 0; j < 10; j++ )
{
//
}
}
Method name should clarify the meaning. Do not use misleading names. If the method name is clear then there is no need of documentation.
Example
Good
void SaveStudentDetails (string studentDetails )
{
// Save the student details.
}
Bad
// This method will save the student details.
void SaveDetails (string student )
{
// Save the student details.
}
A method should do only one job at a time. Do not use it for more than one job.
Example
Good
//Save student details
SaveStudentDetails();
//Send email to user that student details is added successfully.
SendEmail();
Bad
//Save student details
Public void SaveStudentDetails()
{
// First task
//Save student details
//Second task
// Send emails
}
Make sure string comparisons convert string to uppercase or lowercase for comparison.
Example
Good
If(UserName.ToLower()=="tom")
{
// write yor logic here
}
Bad
If(UseName=="TOm")
{
//
}
Comments
Do not write comments for every line of code and every variable declared.
Use // or /// for comments. Avoid using /* … */
Write comments where is it required. But they should be well readable and limited. If all variables and method names are perfectly meaningful, then there is no need for any comments.
If you initialize a numeric variable to a special number other than 0, -1, etc, document the reason for choosing that value.
Make sure to perform spelling check on comments and make sure proper grammar and punctuation is used.
Enum
Always use a singular noun for defining enum.
Example
Enum Mailtype
{
Subject,
Body,
PlaneText
}
Interface
Always use the letter "I" as a prefix with the name of an interface. After the letter I, use PascalCase.
Example
public interface IMultiply
{
int Multiplication();
}