Wednesday, November 21, 2012

What is More Important Thing Than Coding?


 Considering appropriate name is important for programming. When I read Chapter 7 of Code Complete which talks about High Quality Routines, I strongly agreed with idea of Good Routine name. It gives us few key points for naming routine and it is divided into eight:

  • Everything describe the routine does
  • Avoid meaningless, vague, or wishy-washy verbs
  • Don’t differentiate routine names solely by number
  • Make names of routines as long as necessary
  • To name a function, use description of return value
  • To name a procedure, use a strong verb followed by an object
  • Use opposites precisely


It talks about that appropriate name helps us to understand what routine does. Conversely, improper name routines could make us confused. For example, short name of routines could be easy to write, but it will be highly possible that name of routine might be weak name. However, too long name of routine is improper as well. The book says that “Research shows that the optimum average length for a variable name is 9 to 15 characters.”(171) I think that too much described names can be too long name. In addition, Avoiding wishy-washy verbs is important to name routine because some term of words has several meanings and covers huge meaning such as calculate, call or so on. Those wishy-washy words will not be appropriate name for routine.

Of course, appropriate name is good not only routines but also other objects. As I mentioned above, Weak naming variable makes program harder to understand. If we use weak name for other, it makes us confused as well. In my case, I used to write too short names because it was easy to write. Of course, it did not describe what object does. I just described number or string. We can use any term of words for them such as num1, DailyPay, or etc. So, this is why I used to write short name for them. However, if we use any term of words for variables, program can run. However, it can make our brain confused. One day, I wrote a little long program with short variable names. Finally, I got confused. So, nice described variable name is important for programming.

Example:

1:Answer = number1 + number2

2:TotalSalary = NumberDayWorked + NumberHoursWorked

As you see, second example is absolutely better than first one. First one can run, but we do not know and expect what number1 and 2 do. On the other hand, we can expect what Number DayWorked and NumberHourWorked somehow.

No comments:

Post a Comment