Be concise

Before any of you start nitpicking, let me just say this right away: This blog post will not be concise. In fact only very few (if any) blog posts are actually concise. However, when it comes to code – which I want to talk about – being concise is incredibly important. You cannot add 20 lines of comments to explain everything, good code should be self explanatory most of the time.

Let’s start with an example, which I have borrowed from Uncle Bob’s Blog:

While Uncle Bob’s post discusses the if/else in a broader perspective (you should read it), I think we can agree that Refactoring – 2 is the most concise. Anyone (familiar with the syntax of course) would be able to determine what’s going on. They would with the two first examples as well, but they have a lot of redundancy. Keep it short and simple.

Another example that I have seen a few times, is over complicating a boolean return. It would look something like this:

// Over complicated
public bool IsAdult(int age)
    if (age > 18)
        return true;
        return false;

// Concise
public bool IsAdult(int age)
    return age > 18;

Actually, since I’m using C# for my example, I could have made it even more concise, using expression-bodied members. But this is not a blog post about C# specific details (no matter how neat they are).

The examples here are definitely at the simple end of the scale. And if you have some more complex real life examples, where you managed to make them more concise, I would love to see them. But the point of this post remains. Being concise is important. Especially in places where you know people will read (or listen) only briefly. So besides code, this goes for comments, e-mails, Power Point presentations and a lot of other stuff. Almost anything you encounter in your daily work. You can be certain that people don’t spend as much time reading your e-mails, as you would like them to. So make it easier for them. Be concise!

Published by Jakob Busk Sørensen

Software developer, currently focusing on process automation.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: