Maintain your 1k lines of codes and make it more legible.

How would you write your code to make it more understandable?? Do you think there are some coding standards over Internet? Will you be able to follow it strictly??
Precisely saying, yes it’s obvious there are coding etiquette which is followed by various giant IT companies. But the point is, it’s a choice for a Developer as because every developer may have their own convenient way of writing programs.
Here I have mentioned some of the fundamental coding standards which one could adapt it to maintain their code legibly:

1.Formatting
*Line length can be limited to 80-100 characters and not more than one statement per line
*Using of spaces is a good practice instead of using tab
*For every block-like construct (class, method or constructor) following of the rules can be followed:
-Braces are used with ( if, else, for, do, while ) statement even if the body is empty or contains a single statement
e.g
if ()
{

}

-Each time a new block-like construct is opened, the indent can increased by two spaces
-Control statement ( if, else, elseif, switch) can have one space between the control keyword and opening parenthesis to distinguish them from function calls
e.g.
switch (condition){
case 1: action;
break;
default: defaultaction;
break;
}

*Long if statements can be split into several lines when character/line limit get exceeded
e.g.
if ( ( condition1
|| condition2 )
&& condition3
&& condition4 )
{
//code goes here
}

*Assigning value to a variable can have one or multiple spaces on either side of an equals   ( = ) sign in order to promote readability

$short               = 321 ;
$long_variable = 456 ;

*Functions should be called with no spaces between the function name, the opening between the function name, the opening
paranthesis, and the first parameter; spaces between commas and each parameter, and no space betweeen the last parameter
,the closing paranthesis, and the semicolon
e.g.
var = function($var,  $bar,  $small_var);

2.Naming
*Class names can be written in UpperCamelCase

e.g. $LongVariable
*Method names can be written in lowerCamelCase

e.g. $smallVariable
*Constant names can be all uppercase letters, with words separated by underscores
e.g. CONSTANT_CASE
*Local variables and Parameter names can be written in lowerCamelCase

e.g. $variableLength

3.Commenting
*Proper commenting of each method can be done using singled or multiple line comment
e.g.
void function()
{
//this is the content of the body
}

void new_function()
{
/*This method
*passes the variable to
*another function and returns
*Boolean value */
}

Leave a Reply

Your email address will not be published. Required fields are marked *