Monday, February 1, 2021

Can We Please Keep it Simple?


There is a famous quote about software that I have heard attributed to Brian Kernighan:

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."

I do not think you would find a software developer that disagrees with that statement, yet the field is overrun by a culture that seems to value succinctness more than readability.

When I began to write a lot of Perl, I wrote it like I wrote C programs and caught the ridicule of the Perl wizards who told me it was "better" to rewrite it as something that would wind up looking like this:

@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];

I continued to write the code simply with the fewest "Perl-isms" I could. Our hiring budget would only allowed us to hire mere mortals to help maintain it.

Ten year later, the pattern repeats itself. When I write Python, people point out all the extra syntax I do not need, even though it is my deliberate attempt to make things more explicit and readable. Optimizing character and line counts seems to be a reflex for many programmers.

I have grown to abhor this sentence:

"Look what I can do in just one line of code."

This is usually pitched to me in the context of someone trying to convince me of the wonders of the latest, greatest programming language.

Of all the languages I have learned, there have been only a handful of language advances I have encountered where truly "better" syntax was introduced in terms of readability.  Some of them include:

  • try-catch exception handling
  • "finally" blocks
  • "else" for for loops
  • list comprehensions (but only if used judiciously)
  • string interpolations

In general, if the syntactic feature is specific to a language, I will avoid using it.  I shift around writing code in many languages and the more I can do to minimize the context shift, the better.

With software, readability is 99% of the problem to be solved. As Martin Fowler has said:

"Any fool can write code that a computer can understand.  Good programmers write code that humans can understand."

I was inspired to share these thoughts after reading this article that also makes the case for keeping it simple:

 Simplistic programming is underrated

I have also recently read this related article:

Developers spend most of their time figuring the system out

This is definitely in line with my experiences and helps to emphasize how important code readability truly is.


No comments: