Tuesday, May 19, 2009

The useful vice.

    Whats the single most productive way of writing code ? The answer IMHO is - writing as less as possible i.e laziness.
     By 'laziness' I do not mean laziness in general, I just mean laziness towards writing code. I am extremely lazy when it comes to writing code. I have to get over a colossally stupendous amount of inertia to lift my hands and start coding! I try to find every other valid reason to avoid writing code, even if the problem I'm working on has a pretty obvious solution. I find thinking to be much more rewarding :)
     I think really hard on trying to avoid creation of new code. When given a task, I try to come up with various designs and prove it to the client/boss that the new creation might be optimized out or a previously created module could be employed again. But, is this not just the plain old funda of 'reuse' ? Yes, it is reuse, but not merely reuse. Laziness brings a very very strong urge to question every design decision taken(previously by ourselves or the boss or the client) and test (mentally) whether it really brings any good into the big picture (as far as we can see it). The urge is so strong that it never allows me to start coding until I'm totally convinced that every line of code that I'm going to write is indispensable and will never have to be changed(unless there is a major alteration in the design). While hunting for ways to avoid new code I often run into solutions that I could not think of earlier, ways that appreciably reduce the complexity and, arguments to prove to the client that a particular feature/facet is redundant or can be bettered if thought about in another manner. I often just sit still in my chair brainstorming about how I could get out of the situation without writing a single character of code.
     In this way I've saved myself hundreds of lines of code which effectively means I finished coding faster! Also, I am a strong believer in 'lesser code = lesser bugs', so, I've saved myself(and future maintainers of the code) a considerable amount of debugging time too. Another very useful attribute that automatically comes from laziness is - aversion towards complications. Will a truly lazy person ever write complicated code ? Never; unless it is absolutely unavoidable. With such lazily written code, during a code review the programmer is in a position to defend every single line of code he has written. In addition to that, the client/boss is never unhappy to see a programmer thinking rather than just programming.
     Thus it becomes a win-win situation for both of us - the client/boss is glad to know that I am trying my best not to write non-utile code and, I'm happy because I get more time to read my favorite blogs ;)

P.S: I couldn't find a way to write it with a lesser number of 'I's. It might seem that I'm all extolling myself here, but I humbly state that I'm not!

Related Content

1 comment:

Aditya Bhelke said...

Since I'm lazy, I dont read long posts to the end :)
But your first few sentences caught my eye. On that note I would like to add this:
Give the most difficult task to the laziest guy; He will find the most efficient/easiest way to to do it.

Proudly lazy,