-
Functions
- single return value
- should do one thing
- max. 30 lines
-
Commenting
- describe the code in comments appropriately
- if its hack, mention something like this in comments
- // @TODO: Temporary hack, to be refactored
- follow a pattern // @TODO: some message
-
Indentation
- 4 spaces
- make sure you configure your editor to convert tab into 4 spaces
-
Naming conventions
- Class: Noun, PascalCase
- function: Verb, camelCase
- boolean functions: isLoggedIn (starts with is)
-
Exceptions
- mirror, mail to the team
- zend event context problems handle
- log writing
// Format - can be useful for reading/parser building. date | user | context | message | .... ?? // EDIT
-
Code Writing
-
$a = 1 && $b = 2; // Bad $a = 1 && $b = 2; // Good
- Tips
"session $x" // Slow "session", $x // Fast
- 80 Character limit on one line
- Implement null checks
- If RegEx or JSON is used, put them in try, catch block
- Try to use object and property names instead of array index. (maintainability increases) like this:
var a = someArray[2]; // Bad // if index is not available or changed elsewhere, things break var a = someObject['someProperty']; // Good
- Use Prepared statements for SQL queries
- Always perform checks on user's input before saving to DB
- Log things which are necessary
- Don't Repeat Yourself (follow DRY).
- Code reviews
-
Created
May 5, 2015 12:04
-
-
Save vamshisuram/e60cd9d7bb86bb5aa13c to your computer and use it in GitHub Desktop.
A list of rules for better coding
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment