When I started programming well over a decade ago, my first language was BASIC. It was a fun and cute little language where line numbers were not optional and formatting was never a concern (I’m not even sure how you could format it).
Eventually I found my home in a real language, C. It was then that I was first confronted with the issue of formatting. My early code looked a little like this (and yes, I’m ashamed):
static void testfunc() { int j = 0; for(int i=0; i<50; i++) { j = i + j; } }
My thought at the time was, “I’m smart enough to be able to read this code and decipher it later.” My ignorance shined clearly a few months later when I went back in search of a previously written function and found it almost impossible to alter (because it was about a hundred lines worth of code formatted like the example above).
However, this post is not about my ignorance as a young programmer, but rather an attempt to pass on a type of code formatting that I, and all of the others at AzroTech, have found quite clean and the most readable over any other type of formatting we have played around with. NOTE: I do not maintain this is the BEST way of code formatting nor do I pretend to be the first or only person to do it this way, but rather I wish to share with others what works so well for us.
My college professor, a man named Dr. Eland was the first one to show the differences in code formatting and we were actually required to write our code his way (which is the way I want to show you). He gave us three examples of code formatting, which I will show using the PHP language.
Example 1:
function testfunc() { $j = 0; for($i=0; $i<50; $i++) { $j = $i + j; echo $j; } }
Example 2:
function testfunc() { $j = 0; for($i=0; $i<50; $i++) { $j = $i + j; echo $j; } }
Example 3:
function testfunc() { $j = 0; for($i=0; $i<50; $i++) { $j = $i + j; echo $j; } }
From a majority of the source code that I have read from other programmers, Example 1 is by far the most commonly used formatting out there (and in my opinion the WORST). The problem with this type of code formatting is that the curly braces are not even and it becomes very difficult to match up braces (at least until you train yourself to read code like an alien). Our professor explained to us that code formatted like this was born back when keeping file sizes down was a concern. I would say that it’s worth to take the extra space to avoid this type of formatting!
Example 2 bring us closer to better formatting, but it too has a drawback. It does address the issue of matching up braces but fails to truly express the logical hierarchy of the code. For example, what I mean by this statement is that the code within a function, called a code block, should be thought of as a child of that function. When your eyes are scanning through thousands of lines of code, you are generally searching by a function’s identifier and not it’s underlying code. When you are searching, the braces directly under the function declaration header will make it difficult to differentiate between the header and the code block.
Out of all of these methods, Example 3 is the way we prefer to do it at AzroTech. It provides the best of both of the previous examples: matched braces and differentiation between the header and the code. Programming can be difficult enough at times and by formatting our code this way, we have never struggled trying to determine which code blocks belong where. Like my professor years ago, I require our programmers to use this method of code formatting.
Properly formatted code can make you a better programmer! It would be nice if the whole world could just trust us an try programming this way for at least 30 days, but I know that probably isn’t going to happen. This whole post is not intended to be a rant but rather a glimpse into the development techniques of AzroTech. Hope you enjoyed it! ![]()

April 17th, 2007 at 11:49 am
This blog is awesome, go Azrotech.com I agree with everything on here, Can’t wait to read the next one.
B
July 22nd, 2007 at 5:35 am
Green…
You are probably wrong….