Monday, 4 April 2011

Do it Properly

==========
Code Complete (Steve McConnell)
- Highlight Loc. 27111-19  | Added on Thursday, February 24, 2011, 07:19 AM

Making code readable is not an optional part of the development process, and favoring write-time convenience over read-time convenience is a false economy. You should go to the effort of writing good code, which you can do once, rather than the effort of reading bad code, which you'd have to do again and again. "What if I'm just writing code for myself? Why should I make it readable?" Because a week or two from now you're going to be working on another program and think, "Hey! I already wrote this class last week. I'll just drop in my old tested, debugged code and save some time." If the code isn't readable, good luck! The idea of writing unreadable code because you're the only person working on a project sets a dangerous precedent. Your mother used to say, "What if your face froze in that expression?" And your dad used to say, "You play how you practice." Habits affect all your work; you can't turn them on and off at will, so be sure that what you're doing is something you want to become a habit. A professional programmer writes readable code, period.
==========

This comes back to integrity. You do something because it is the right thing to do, not because you're afraid of being found out. I have to admit, there is some code in the Android application that I wrote that isn't too pretty. I justified it to myself by saying that I was the only person looking at the code, therefore it didn't matter if it was a bit ugly. Of course, I ended up cursing myself when I returned to make a change or add a new feature!

It's amazing how quickly you forget about code that you have written. That's why it's important to do it properly the first time (with comments) even if you are the only person that will be looking at the code.

I write this not to convince you, dear reader, but to convince myself. You, I am sure, write perfect code every time.

No comments:

Post a Comment