COV

What should and shouldn’t be hard

Why would anybody want to code? Probably because somebody wants to solve a particular problem with a piece of software and hopefully because that somebody likes to write - we’re usually better at the things we enjoy. And writing is very important in programming. This is no new insight, in fact it’s quite old. Yet, it doesn’t seem stick.

Programming can be a very daunting experience. The saying, that programming is hard enough as it is and that we should not make it any harder is probably undisputed. What might to be challenged is the understanding about what it is, that makes it hard. Often we’ll lean towards the position that the hard thing about writing code is the writing – it should be, but unfortunately often it’s not. Often reading a piece of code is a lot harder than writing it obviously was.

We often do not take the time and effort necessary while writing. Knowingly or not, we think we make our lives easier by cutting corners, only to make it a lot harder later when we, and others have to read the code. And since code is read many more times than written this really adds up.

Even if it might be very hard to put into words what’s in one’s mind, it’s a lot harder for anybody else to decipher poorly worded quick-and-dirty dumps of random thoughts. And that goes for any writing, be it a novel or a computer program.

The hard part really should be the writing. Doing it right should be really hard because that would mean we’re putting a lot of thought, time and energy into it. Reading it on the other hand would then be very easy, even fun.

Example: Identifiers

Just like an written words, programs are made up of a lot of those. Over the few keywords we have basically no power. But the majority of the words are created and chosen by the programmers. Those identifiers are the words that can make a program very hard or a delight to read. As the name suggests they are identifying things, they are naming variables and functions and the like. Good identifiers can make a program readable like a well written book, a book that’s even fun to read, because in the case of a program it reveals the intent of the code we’re reading. Badly written programs do not do that, we have to read it again and again, make any number of mental notes about what certain words actually mean and have to remember counterintuitive facts that are otherwise utterly useless. All of that comes at a terrible cognitive cost, energy that’s wasted and that can’t be put to good use anymore. Deciphering such programs and words is very hard – it is something that can make programming very hard.

Finding good names for things, creating and choosing good words for abstract concepts is part of what makes programming fun to do. Those creations are what makes it easy and a joy to express what's in one's mind in a simple, elegant and very expressive computer program. But doing it and especially doing it right is also very hard, it takes time, thought and practice.

Unfortunately there’s a shortcut by not paying too much attention to the writing. When we do that, we, and every single programmer that comes after us will have a much harder time reading. Only then there will be no shortcuts available, and at that point we have to admit that we made the life of somebody else needlessly harder and their job possibly frustrating - and for no good reason at all except for selfishness and/or lack of skill and experience.