Blog moved to

Tuesday, August 7, 2007

Coding Conventions

Note: Following content deals with computer related stuff. Reader discretion is advised.

I was helping(read as 'trying to help') a teamie in coding today. That actually made me to touch "My-Bic = Easy Ajax"  for coding a web application in PHP which includes lot of Ajax. I told my teamie that use of My-Bic "framework" makes Ajax work very simple.

It's true that My-Bic makes work very simple. But, I was wrong in using one term there. Whenever I use that word with My-Bic I feel tingling in my head that I'm using a wrong term. Yeah, the term is "framework". My-Bic is a basic state of mind system rather than a frame work as per and also, its simple, fast and easy to use. Actually, this blog entry is not to write about My-Bic, but to write about something else. Yeah, about the title "Coding Conventions". I will come to that after telling thanks to My-Bic for my "Happily Ever After" combination of Ajax and PHP. Guys, thanks a lot for moving pain of many programmers to /dev/null

Now, coming to Coding Conventions. I had a feeling that coding convention is a same thing across all the programming languages. Yeah, I ended up as a stupid with wrong assumption. Today, I saw that there are so many conventions for each and every programming language though only one is standard. Yeah, one standard convention for one programming language.

For fellow PHP programmers reading this page out there, I just saw a set of conventions on a site which gives opensource Ajax Framework (I'm going to try it very soon as its a Framework) The name is Mouse, TigerMouse. It's considered as a very good framework available now. I will confirm whether its easy to use or not (If I can use, it MUST be easy to use) it very soon after trying that out.

Some of the conventions given are (except naming class file, all the following are same in php and Java)

  • class names in PascalCase (e.g. ClassName)
    • I do follow this convention YAY !! (+1 point)
  • methods, properties and local variables names in camelCase (e.g. methodName)
    • I follow this one too !!!! (1+1 = 2 points)
  • class files <class name>.class.php
    • I've coded a class today and I dint follow the above one. Its not same in java. (2 - 1 = 1 points)
  • only one class/interface per file
    • Yes. I do that in both java and php (1 + 1 = 2 points)
  • keep { in the same line as its respective if, for, function, class, etc.
    • Arghh, I always hated this thing. I always keep { in the next line. Duh @ this convention (2 - 1 = 1 point)
  • document your code using Doxygen tags
    • Excusez moi, did I just use the word "document" .. uhmm. //No Comments ( 1 - 1 = 0 points)

Man, being a person who actually codes (not a lot, but, I do code) with conventions in my mind, I scored 0 points for PHP and 1 point for Java. Those conventions make your fellow programmers' lives simpler if they have to hack your code. Just for my friends who follow this blog, though most of them are not into programming now .. I guess, but, if they've to code sometime (in any language, not just php/Java) please take sometime to read conventions of that specific language, and do follow them while coding and give your fellow programmers more time to hack the code rather than try to understand the code.

0 responses:


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.

I'm not a lawyer to tell this in a perfect framed sentence. Frame it by yourself if you are so concerned.
Dont think about the content of this blog. Every byte is owned by its rightful owner.
Rest © 2006-2007 Karteek