Almost every day, someone is telling me that this or that code is not clean. Not readable. Not maintainable.
But there are some gaping logic farts with this whole concept.
Any teacher knows it is vitally important to know your audience. A talk that is spot-on for one person may be completely incomprehensible to another.
The same is true for code.
As a teacher of code, I can’t count the number if times I have showed the class some new language feature/pattern/idiom only to have some student inform me that they will not be using said feature/pattern/idiom because it makes the code completely unreadable and unmaintainable.
The first time I saw JavaScript destructuring I swore it was unreadable and refused to use it. But somehow, miraculously, I now use it every day and couldn’t live without it. And I find it makes my code more concise and readable. The same is true with JavaScript’s spread operator. And countless other language features/patterns/idioms.
The first time I tried to do functional programing I thought it was God-awful. Why the hell would anyone want to do that? Today, it is completely intuitive and useful and, for me, easier to read and maintain. Today I use map, filter, reduce, higher-order functions almost every day and find the code concise and readable.
I think that “types” make my code more self-documenting and readable. My partner thinks it makes code less readable.
When calling a function, Ruby, Groovy and Kotlin allow you to put the last argument after the parentheses (if that argument is lambda). If you look at some of my older older code, you will see that I refused to use that feature. I found it hard to read. Now I love it and I think it makes my code more readable. It is literally one of the most useful features of the language. But just yesterday, one my best friends (and a very smart guy) insisted that this feature is awful and makes code harder to read.
Bottom line:
- It is almost impossible to distinguish unreadable from unfamiliar. If a coder tries to tell me that this or that code is unreadable and I tell them it’s unfamiliar not unreadable, they will me fight to the death to have their way. I have never won that argument. Never.
- Code that I once thought was hard-to-read is now concise, clean and readable.
- One person’s clean code is another person’s spaghetti.
This is not to say that there are not some universally good ideas regarding readability. But that is a different topic.
If there is a language feature/pattern/idiom that newbies on your team find unreadable, should you avoid said feature/pattern/idiom? Or should the newbies step it up?
Finally, any code that I deem as readable is readable. Everyone else is wrong. 😀