International School of Engineering Web Software development Development Decoded
Home Products Allmostapp Testimonials About Us
one pix   one pix   | |
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


Comments for “Coding guidelines and best practices”

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 - 2017 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