Saturday, January 15, 2011

PHP code refactoring - is my understading

1. If existing code has redundant code, I will create common method or class for that & I will call wherever I want.

2.Code Indentation: So that any user can easily understand the hierarchy of the codes.

3.Include comments for each functionality, in order to clearly explain what the particular code is all about.

4.Code simplicity like avoiding generation of unnecessary loops to fetch a single value.

5.While fetching records from the database, its best to avoid select * and instead add particular field names like "select username", "select password".

6. It is very helpful to use "Extract" keyword for parse the array-based outputs using Ajax. For example there would be no need to get connected to the database every time.

Ref: http://www.macronimous.com/resources/the_need_for_PHP_code_refactoring.asp