Live data from Hacker News

Good code is rarely read

alexmolas.com

31–40 of 115 posts

Re: Good code is rarely read

#33

This feels borderline tautological: good code is good because it’s good. Good or bad, you’re going to end up needing to add new features to this code. Or someone misunderstood an input or output to/from this code and you’ll need to read through it to understand how it’s implicated in a bug. I think ‘good code is easy to read’ is pretty profound: DRY code with the right abstraction is easy to read. DRY code with the w…

It's because they are using "read" to mean "understood/interpreted" in the sense that the reader is executing the program in their head.

In their last paragraph:

  It should be so well-structured and named that its purpose and functionality are immediately apparent [when read]. This minimizes the need for others to read through **and interpret** the code, allowing them to use it more effectively.
(emphasis added)

So the point is really: "Good code should be so apparent that when the reader reads it they do not have to be a human interpreter."

Re: Good code is rarely read

#34
Code quality and how often it is read are mostly orthogonal.

You can have an stinky old piece of legacy software that no one ever reads because that system is deprecated and slowly getting phased out, and we can live with it in the meanwhile.

You can have the most elegant a beautiful piece of code that gets read a lot, because it is in the critical path of a very active and rapidly evolving system, and people need to reference, modify and extend it a lot.

However there is a crucial way where OP is wrong: there is a pull and push between code quality and how often it is read. If your code is a legacy big ball of mud, people will be less inclined to touch it, probably going to the extend of rewriting the whole thing. On the other hand when code is well written, people are less afraid of digging into it.

Lastly, even if OP thesis was correct, I don't know think it would change anything. Strive to write the best code you can within reasonable constraints, independently of how much other will read it (which in my experience is almost always underestimated).

Re: Good code is rarely read

#35

This feels borderline tautological: good code is good because it’s good. Good or bad, you’re going to end up needing to add new features to this code. Or someone misunderstood an input or output to/from this code and you’ll need to read through it to understand how it’s implicated in a bug. I think ‘good code is easy to read’ is pretty profound: DRY code with the right abstraction is easy to read. DRY code with the w…

Have you ever had the need to read the source code of a tool because it doesn't behave the way it should, and its help and documentation prescribes?

I have been there a couple of times, and how some stuff is handled in these codebases were sad. Sloppy, assumption ridden, or pure, inelegant and fragile hacks.

Even if you're reading a code to modify it, good code is easier to follow and read (point of the junior developer), and as a result, you touch less and less parts of the code to develop it even further.

So yes, Good code is rarely read, or "read less, and in more niche cases".

Re: Good code is rarely read

#36
Hm, I would agree more with the overall headline and conclusion if it was about time spent reading code.

The best code and code bases allow you to quickly understand how they are structured and don't necessarily hold subtle, nasty surprises - or at least make it obvious if something is a nasty, subtle surprise. Those code bases tend to be a quick read.

The bad functions and code bases require you to carefully consider every little aspect of every single line in detail. And I don't just mean "read every line", I mean "Dissect lines based upon language specs, and also keep in mind this is interacting with 5 different other parts of the code base. Or not. Who knows?" In such code bases, just figuring out what something does tends to be a slog.

Re: Good code is rarely read

#37

This feels borderline tautological: good code is good because it’s good. Good or bad, you’re going to end up needing to add new features to this code. Or someone misunderstood an input or output to/from this code and you’ll need to read through it to understand how it’s implicated in a bug. I think ‘good code is easy to read’ is pretty profound: DRY code with the right abstraction is easy to read. DRY code with the w…

Most essays about good code seem to end up being tautological.

The good ones dont.

Re: Good code is rarely read

#38
> Good code is so ergonomic that you almost don’t need to read it; you just use it.

This is a poor world view and is what leads to unwieldy systems with weird interactions that are buggy in just the right situation.

I understand what the author was trying to express, but the sentiment is poorly expressed. They conflate "used"/"run" with "read" several times. IME, good code is readable code, but not all readable code is good code. Clever code is normally much less readable. At the end of the day, the lifecycle of any code you produce is such that it will generally be maintained far beyond the time is was written. To me that means you need to write code with maintainability in mind. If you cannot read and understand the code, how can you expect the effectively maintain the code?

Simply having a clearly defined function name, arguments, and documentation doesn't mean you can ignore making the innards maintainable.

Finally, as others have pointed out, you want your colleagues reading good code so they can learn to write better code. No matter your level, you should never stop learning to be a better developer.

Re: Good code is rarely read

#39
Genuinely, one of the worst think pieces I've seen this year.

How does the author presume to know how to use something without being able to read it's interface or related documentation? The very things that make something easy to use, like clearly naming things, also makes it easy to read.

I would even argue that reading what the underlying code does is always good practice. Even if you think you know how something works, confirming it can avoid nasty bugs. Not to mention all the projects that are non-trivial and have enough complex behavior that reading the code is the best way to understand what it does; where there is no other way for it to be easy to use according to the author. There's also lots of other benefits, such writing code that is more consistent and more semantic with the underlying style.

Just horrible, horrible advice.

Re: Good code is rarely read

#40
post #30

Those who are disagreeing with the author seem to not realize that he's just engaging in a bit of navel-gazing wordplay. Sort of like when people say "good programmers should be lazy". What they really mean is that good programmers should think ahead and craft their code with an eye minimizing future modifications. Similarly, I think the author is simply saying that well written, easy to read, easy to understand code…

The corollary of the author's argument would be that no C++ code is good ;)
Post reply on HN