Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-settings.php on line 512

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-settings.php on line 527

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-settings.php on line 534

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-settings.php on line 570

Strict Standards: Declaration of Walker_Page::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1199

Strict Standards: Declaration of Walker_Page::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1199

Strict Standards: Declaration of Walker_Page::start_el() should be compatible with Walker::start_el(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1199

Strict Standards: Declaration of Walker_Page::end_el() should be compatible with Walker::end_el(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1199

Strict Standards: Declaration of Walker_PageDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1244

Strict Standards: Declaration of Walker_Category::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1391

Strict Standards: Declaration of Walker_Category::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1391

Strict Standards: Declaration of Walker_Category::start_el() should be compatible with Walker::start_el(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1391

Strict Standards: Declaration of Walker_Category::end_el() should be compatible with Walker::end_el(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1391

Strict Standards: Declaration of Walker_CategoryDropdown::start_el() should be compatible with Walker::start_el(&$output) in /home/celeroo/public_html/blog/wp-includes/classes.php on line 1442

Strict Standards: Redefining already defined constructor for class wpdb in /home/celeroo/public_html/blog/wp-includes/wp-db.php on line 306

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-includes/cache.php on line 103

Strict Standards: Redefining already defined constructor for class WP_Object_Cache in /home/celeroo/public_html/blog/wp-includes/cache.php on line 431

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-includes/query.php on line 61

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-includes/theme.php on line 1109

Strict Standards: Declaration of Walker_Comment::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/celeroo/public_html/blog/wp-includes/comment-template.php on line 1266

Strict Standards: Declaration of Walker_Comment::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/celeroo/public_html/blog/wp-includes/comment-template.php on line 1266

Strict Standards: Declaration of Walker_Comment::start_el() should be compatible with Walker::start_el(&$output) in /home/celeroo/public_html/blog/wp-includes/comment-template.php on line 1266

Strict Standards: Declaration of Walker_Comment::end_el() should be compatible with Walker::end_el(&$output) in /home/celeroo/public_html/blog/wp-includes/comment-template.php on line 1266

Strict Standards: Redefining already defined constructor for class WP_Dependencies in /home/celeroo/public_html/blog/wp-includes/class.wp-dependencies.php on line 31

Strict Standards: Redefining already defined constructor for class WP_Http in /home/celeroo/public_html/blog/wp-includes/http.php on line 61

Strict Standards: Declaration of AVH_Walker_Category_Checklist::start_lvl() should be compatible with Walker::start_lvl(&$output) in /home/celeroo/public_html/blog/wp-content/plugins/extended-categories-widget/widget_extended_categories.php on line 290

Strict Standards: Declaration of AVH_Walker_Category_Checklist::end_lvl() should be compatible with Walker::end_lvl(&$output) in /home/celeroo/public_html/blog/wp-content/plugins/extended-categories-widget/widget_extended_categories.php on line 290

Strict Standards: Declaration of AVH_Walker_Category_Checklist::start_el() should be compatible with Walker::start_el(&$output) in /home/celeroo/public_html/blog/wp-content/plugins/extended-categories-widget/widget_extended_categories.php on line 290

Strict Standards: Declaration of AVH_Walker_Category_Checklist::end_el() should be compatible with Walker::end_el(&$output) in /home/celeroo/public_html/blog/wp-content/plugins/extended-categories-widget/widget_extended_categories.php on line 290

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-content/plugins/g-lock-double-opt-in-manager/glsft-optin.php on line 2895

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-content/plugins/g-lock-double-opt-in-manager/glsft-optin.php on line 2904

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-content/plugins/g-lock-double-opt-in-manager/glsft-optin.php on line 2906

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-content/plugins/g-lock-double-opt-in-manager/glsft-optin.php on line 2910

Deprecated: Assigning the return value of new by reference is deprecated in /home/celeroo/public_html/blog/wp-content/plugins/g-lock-double-opt-in-manager/glsft-optin.php on line 2919

Strict Standards: Declaration of id_comment::export() should be compatible with id_data_wrapper::export($bRemote = true) in /home/celeroo/public_html/blog/wp-content/plugins/intensedebate/intensedebate.php on line 658

Strict Standards: Declaration of id_post::export() should be compatible with id_data_wrapper::export($bRemote = true) in /home/celeroo/public_html/blog/wp-content/plugins/intensedebate/intensedebate.php on line 759

Strict Standards: Non-static method sem_google_analytics::init() should not be called statically in /home/celeroo/public_html/blog/wp-content/plugins/sem-google-analytics/sem-google-analytics.php on line 407

Strict Standards: Only variables should be passed by reference in /home/celeroo/public_html/blog/wp-content/plugins/slayers-custom-widgets/slayer_Custom_Widgets.php on line 50
Celeroo’s Blog and Training Center | Coding guidelines and best practices
International School of Engineering Web Software development Development Decoded
Home Products Allmostapp Testimonials About Us
one pix   one pix   | |
PHP  
Bookmark and Share
Add to Technorati Favorites

Coding guidelines and best practices

This entry is part 2 of 3 in the series Recipe for Great PHP Programming

Previous Article in this Series
Writing enterprise class code in PHP


Rapid Application Development

Your customer will, of course, want you to develop applications as fast as possible without compromising on scalability and maintainability.

Besides improving your coding skills, there are a few other options that can enhance the speed of development.

  • Use a framework: A framework provides you with a rich set of functions and classes to do common tasks and is useful in many ways. It speeds up the development by saving a lot of coding time. Also, having well developed and tested units for common tasks reduces bugs and poor design decisions.
  • celeroo-smiley Learn more about Celeroo Frame, a lean, flexible and transparent PHP framework, and download for free.
  • Create your own libraries: If you practice abstraction, you will soon end up with a lot of reusable code (functions, libraries etc.).
  • Follow standard coding practices: By faithfully following coding guidelines you save the time of reinventing design patterns, digging through the code and documenting more than needed.
celeroo-smiley Celeroo Builder is a web software development tool that includes the above benefits and automatically generates code that you can deploy in your server. Learn more about Celeroo Builder.

So, What is a Good Coding Practice?

Well, there is no single answer to this. Basically, what you need is to create a set of rules and follow them faithfully every time you code.

Here are some general coding guidelines you should follow:

  • Write short PHP scripts, to the extent possible.
  • When more functionality is needed, place it in functions, classes or plain include files.
  • Avoid too much if/else nesting. If more than 3-4 levels of nesting are required, this probably means the code is not designed well. In case 4 or more levels of nesting can’t be avoided, place the nested structures in include files or functions.
  • Always indent blocks of code coming after if, else, for, foreach, while, switch/case , etc. control flow structures. For indenting, either a single tab or 3-4 spaces can be used. This is very important for code readability.
  • Avoid writing if/else statements without the opening and closing brackets {} except when the code in them is really short and can fit on a single line without any word wrap.
  • Avoid repeating pieces of code. If identical code (5 or more lines) appears two or more times within one or more scripts, they are good candidates for wrapping in a function or a class.

Rule to form your own rules

You can write your own rules. But, know that there is nothing worse than a set of rules which do not make sense. For example, using the Hungarian convention for PHP variable names has very little use because the variables can change their type.

Additionally, the 3-4 extra characters it adds before the variable name may not look like a big overload, but multiply it by a million (a good guess for the number of variables in a large project) and you will see a waste of 277 person-hours.

To create only coding rules that make sense is not that hard - for each planned rule you need to ask why and be able to answer with because.

In the next article, we will share with you some rules that we follow ourselves.


Next Article in this Series
Naming conventions and guidelines



Discussion

Comments for “Coding guidelines and best practices”

 
OUR PRODUCTS
Celeroo Req 'n Spec
Smartest Way To Manage Requirements And Changes For Any Software Project   more
 
Free Trial Req 'n Spec
Celeroo Builder
Cheapest And Fastest Way To Build PHP Applications   more
 
Free Trial Builder
Celeroo Frame
Lean, Flexible And Transparent MVC PHP Framework       more
 
Download Frame

Subscribe to "Allmostapp: Empowering BAs to Build Apps from Ideas - Swiftly"

We will NOT share your info with any third party. PERIOD.
 
right-bg-img right-bg-img
  Who We Are | Contact Us  
  All Rights Reserved. Copyright © 2008 - 2016 International School of Engineering. Celeroo’s Blog and Training Center . Entries (RSS) Search Unleashed wordpress-email-newsletter-plugin-for-double-opt-in-subscription G Lock Powered by WordPress Theme by The Masterplan