Following a coding standard ensures better readability and consistency. Also, when working on larger projects with multiple developers, it helps to keep the diffs fewer in a version control system. Some coding standard recommendations are given below.
Code indentation:
Instead of using a tab, we recommended indent of 4 spaces should be used because different systems use different settings for a tab.
Line length:
It is recommended to keep lines at approximately 75-85 characters long for the sake of better code readability.
Control Structures:
These include if, for, while, switch, etc. Control statements should have one space between the control keyword and the opening parenthesis, to distinguish them from function calls. You are strongly encouraged to always use curly braces even in situations where they are technically optional.
<?php
$n = 5;
if ($n > 0){
echo "Positive";
}
elseif ($n < 0){
echo "Negative";
}
else{
echo "Zero";
}
?>
Comments:
standard C++ comments (//) and C style comments (/* */) are both fine. Use of Perl/shell style comments (#) is discouraged.
Tags:
Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is required for PHP compliance and is also the most portable way to include PHP code on different operating systems and setups.
Variable Names:
- Use all lowercase letters
- Use ‘_’ as the word separator.
- Global variables should be prepended with a ‘g’.
- Global constants should be all caps with ‘_’ separators.
- Static variables may be prepended with ‘s’.
Function Calls:
Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon.
$var1 = fun($bar1, $baz1, $quux1);
Function Definitions:
function foo1Function($arg1, $arg2 = '') {
if (condition) {
statement;
}
return $val;
}
jQuery allows the user to create powerful and dynamic webpages that run without any hiccup. With StudySection, you have the liberty to choose among beginner or expert level jQuery Certification Exams to help you excel in this career field.