Wednesday, June 6, 2012

Programming is a matter of state of mind

Many years ago, a senior programmer once said to me something like “to be a good programmer, you need to have 2 characteristic, one is logical thinking, another one is common sense.”
 
In my code review process, when I pointed out that update logic should not be in a “CREATE” stored procedure (USP_CREATE_INDIVIDUAL_ADDRESSES with the comment saying: This SP creates collection of records in XXX Table)
 
When I pointed out that some code like following does not make sense:
IF(@I_CUSTOMER_ID = 0)
      SET @I_CUSTOMER_ID =0

IF(@I_INDIVIDUAL_ID = 0)
SET @I_INDIVIDUAL_ID = 0

The responses I got were something like: okay, we will rename it; okay, we will take these code blocks out. As if these are not big deals, it was just me being picky.

To me, these are big deals to any programmer.  For sure, we programmers write program with bugs, I have my fair share of bugs in the code I wrote. In most of time, the bugs are introduced by we forgot to handle certain scenario, or we missed a piece of business logic.  That’s fine, because we are human. From time to time, human tend to forget things or overlook things.

It is not fine when we programmer write code without logic thinking, without common sense. At any point of time when we write program, our state of mind need to be very clear on what we want to do and how we do it. When a programmer wrote some code like the code block above, what was his or her state of mind when he or she hit the keyboard? When a programmer decided to extend the scope of the stored procedure from “Create” to “Update” without renaming or added comment indicating so, did that come across to his or her mind that it would create confusion for the fellow team members? What was his thinking process when he or she hit the keyboard put these code blocks in?
 
If these coding practices came from the same programmer or the same team, how confident you are on other code written by them?

Martin Fowler once said “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.” I figured that’s because we human read the program with the goal of figuring out what it try to do with logical thinking and common sense, while computer reads the program with the goal to do what it is instructed to do even it does not make sense. Like people use natural language communicates with people around them, programmers use programming language to communicate their thinking with fellow programmers.  Through listening to what a person say, we get to understand one’s state of mind; through reading the program a programmer wrote, we also get to understand one state of mind. To any programmer, State of Mind matters the most!   



No comments:

Post a Comment