Sunday, October 3, 2010

Are we smart or what

I have been developing application in more than 7 computer languages for about 7-8 years. Sometimes I wonder how many people out there are truly passionate about technology and have dedicate some part of their life for self-improvement.

Most of the coders hired by big companies are freshers. Anybody can code, true. Then there are people like me who have to study each and everything in order to maintain that soggy piece of software.

But this post is not about criticizing ways of the world. I'm highlighting how much a readable code means to a maintenance/sustenance team. One of the tip is this -

If you have see a function having a boolean argument, do not use it, if possible. Try to break that function down in two functions with readable names which depict their intentions clearly.

Why do I say so? I say because boolean parameters are not made for readability. They are just a type to differentiate two ways of processing. For example:

void Greet(string message, bool world)
{
    if (world)
        Console.Writeln(message + " world!");
    else
        Console.Writeln(message + " me!");
}

Now, using it seems strange:

Greet("Hello", false);
Greet("Hello", true);

If we break it down to two functions, namely, GreetWorld and GreetMe, then it becomes more readable and understandable.

void GreetWorld(string message)
{
    Console.Writeln(message + " world!");
}

void GreetMe(string message)
{
    Console.Writeln(message + " me!");
}

//Usage
GreetWorld("Hello");
GreetMe("Hello");


There are many standards set for coding. But most of them are same old crap. Think differently.

No comments:

Post a Comment

Talk to me :)