Everyone should follow some coding standards. It is required because there may be many developers working on different modules of one project; if they follow their own standards the code may become very un-manageable. It is very difficult to maintain the code in future.
Reasons to follow standards:
- Your co-programmers should understand your code. A coding standard acts like a blueprint for the team.
- Simple and clear code will reduce your common mistakes.
- If you revise your code after some days, it is easy to understand that code.
- For best quality project you should follow the coding standards.
Here are some coding tips to follow for better result:
- Text indenting and line length: It is better to maintain text indenting and particular line length while coding. For text indenting use four spaces instead of tab, because different computers may take different settings for tab. It is better to maintain the line length approximately 75-85 characters long for better reading.
- Control structures: Control statements should have one space between keyword and opening parenthesis, to make a difference between function calls and control statements. It is recommended to use curly braces even though it is optional.
- Function calls: Functions should be called with no space between name and opening parenthesis, and the first parameter, spaces between commas and each parameter, and no space between last parameter and closing parenthesis.
- Function definitions: Function names should follow the allman style.
- Comments: Use C style comments (/* */) and standard C++ (//) style comments.
- Variable names:
- Use lower case letters
- Use ‘_’ as word separator.
- Global variables should be prepended with ‘g’
- Static variables should be prepended with ‘s’
- Global constants should be all caps with ‘_’ separator
7. One statement per one line
Here is the set of tips to follow to become a good PHP developer.
- Don’t use PHP short tags:
Short_open_tags is an ini setting. By default it is enabled in PHP 5.3, but every server not run PHP 5.3. It is more important to use PHP full tags in compatibility and portability.
2. Stop using MySQL Library:
It is better to stop using MySQL library functions as they have not updated in some time.
Use MySQLi or PDO
3. Use array functions and string functions:
While working with arrays and strings it is more important to use functions instead of writing your own code.