The Quality in the Code

Posted on December 17, 2006. Filed under: Musings |

The bugs are always in the code.  The programmers till now have been creative types, but most of them did not have any grounding in mathematics or logic.  Some of the freshers I see today dont even know much about flowcharts, binary, hexadecimal, etc.

 Anyway, I am making a much more finer point.  The way we write a loop.

for(i=0;i<10;i++)

This manner of writing the loop is popular because this is the way it is taught.  I have always found it irritating because this is a half-open interval.  I would prefer to write it as a closed interval, like this:

for(i=0;i<=9;i++)

Big deal, you say?  What difference does it make, you ask?  They both work the same way, you exclaim!  That just goes to show how difficult it would be to reach quality in the code.  At the level of pseudocode, such things should be standardized ( or recommended)..

when writing a counting loop, always use closed intervals.

This should apply whether you are writing in java, c, python, ruby, whatever. 

Instead we have people talking endlessly about how to name variables and do indentation.  These things do not affect quality, and dont need to be done manually.

Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

  • Posts

  • del.icio.us

  • Blog Stats

    • 77 hits
  • Meta Information

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: