Tuesday, December 11, 2012

Coding Practices

In the name of ALLAH who is most beneficent and merciful 


Few days back , while we were working on CMS projects, I made a list of few practices that I think one need to adapt to have better code and work. May be I will add more items in following list and I think that one can do work in much better way, if take following guidelines in mind. So below are the items of my list.

  • Try to always safely remove extra code, there shouldn't be code unless there is reason
  • Try to adopt standardized approach as much as possible
  • Avoid setting criteria based on string formatting, it is confusing and sometime not as much easy to process, in terms of performance also, specially when case sensitive and not defined properly that can be very messy
  • In any software system, if filesystem and DB are being used side by side then they should either be kept seperate or need a proper way to sync them
  • try avoiding function call in condition in both control statement or loop
  • In comments tell what a function expect, what it return and what it set to other variables that are available in same request's scope
  • Naming convention everywhere whether it is table, keyword , field or variable or function , should be consistent to avoid confusions
  • In DB, whenever there is need of having only one of different option per record then in that case enum or association with another table can be better than having many boolean fields while only one field will get data
  •  A function should be only doing exactly one thing
  • Try to limit function to maximum 20 statements

  • Function should be understandable in almost 30 seconds

  • Whenever you are struggling at one problem and every thing seems fine but still problem is not fixed then may be you are struggling at either wrong solution/way or wrong problem, so need to think again

  • Avoid global variables and functions usage as much as possible, it can cause serious problems if user don't use it properly

  • If anything is changed during work , something on which other things depends, communicate about that if others team members are working around that, even it is one line of code
     
  • Even in good communication environment, there is not always time for communication, so follow standard coding practices defined as good practices or set by your team.
  • Classes and methods should have their useable data in passed arguments or there in their object, shouldn't be depend upon outside world
    I hope that using above guidelines can help you in doing your daily development work better. 
    thanks

No comments:

Post a Comment

I shared here what I thought, will you please share your thoughts ?