Friday, November 19, 2010

What's more important? Readability!

Alas, in all the comments on this posting, nobody put readability first...


What's more important?

What's more important, for your code to be readable, or for it to be right?

Sorry, nobody gets to reject the premise of the question. If you code at all, you already have an answer, it's written right into the product of your labors.

How about this: What's more important, for your code to be correct, or for it to be fast?

I know my answers, what's yours?
I mean sure, we can debate what "readability" means, but what does it mean not putting it first? Do you have so little respect for yourself that you want to make your life more difficult rather than easier?

If a piece of code is not readable, how exactly do you ensure that it is correct? Oh, right... by testing... let me know how that works out for you.

If a piece of code is not readable, how exactly do you fix it when it fails to work properly? Well, if you're me, you start by rewriting it so it's readable.

If a piece of code is not readable, how exactly do you improve it's performance? Well, if you're me... same answer.

But, apparently, that's just me...

I am alone

2 comments:

Graeme said...

You said that nobody gets to reject the premise of the question. Watch me.

The question you answered was "Is readability important?" and I absolutely agree with your answer. However the question you asked was "What's more important?", i.e. if you have a choice of exactly one of the options, which do you choose? If there can be only one, correctness is the only answer. You go explain to a CFO that even though the annual report he released has incorrect information because your product messed it up, it's OK because the code is readable.

Of course in the real world, you don't have to choose only one, so the question is academic anyway.

Breck Carter said...

The question was "What's more important?" not "What is the only requirement?" I claim readability comes first, you have a different opinion, that's fine. The CFO story is a straw man argument; i.e., it argues against a position that was never stated or implied... of course everyone strives for correctness, and the work isn't done until it is achieved to the best of our abilities. You claim it is an academic question, that's your right, but my experience points to the opposite: the world is awash in code that is incorrect precisely because correctness came first during development, at the expense of readability. Readability is not an optional add-on feature, it is a prerequisite for correctness (and performance)... again, my opinion, one which, apparently, few share :)