AzroTech
Websites + Web Applications + Software Development

A glimpse into the world of AzroTech's development and technology

Official AzroTech Blog

Archive for the ‘Misc’ Category

Technological Brew

Tuesday, June 12th, 2007

So it’s been awhile since the last post and you may or may not be curious as to what the tech-savvy folks at AzroTech have been up to.

One of the key focuses of our research has been making the switch from PHP to one of the cool new Web 2.0 frameworks/languages for all of our future (and top secret) web apps. The two contenders are Django (Python-based) and Ruby on Rails (Ruby-based {as you might have assumed…}). We are still torn, but a decision will be reached quite soon.

Also, we have been hard at work developing a new Javascript framework to clean up many of the namespace polluting functions that we already have. Yes, we are ashamed it took this long, but at least we are making the leap.

Aside from the all of the projects we are working on for our many happy and wonderful clients, we have begun strategizing a fresh new AzroTech Update. It is going to be even more amazingly simple to use and will also allow for portability. That means you can still enjoy the benefits of AZ Update even if you don’t host with us.

Finally, do yourself a favor and add the AzroTech blog to your RSS aggregator. We are launching a new initiative to blog every day with updates and technical issues we run into while doing what we do. We will include topics from database development, new technologies, C#, PHP, Ruby, Python, CSS, and web standards. Tune in and enjoy!

The importance of properly formatted code

Monday, April 16th, 2007

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! ;)