News for hackers. Stuff that matters.
Re:Good code is rarely read by aaronbrethorst on Saturday June 15, 2024 @10:28AM (#40690039)
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 wrong abstraction is hard to read.

Re:Good code is rarely read by chaboud on Saturday June 15, 2024 @10:58AM (#40690208)
There’s a thin sliver of things I have read through that I considered good (even great) that were high effort to read. Things like STL, boost (in parts), numpy… huh. Come to think of it, all things that use C++ templates… and I’m a big fan of templates…

The thing they all have in common is that they are/were overwhelmingly useful to people who didn’t need to go digging inside of them to use or understand them. These are bodies of code for which the behavioral and algorithmic properties were documented thoroughly, bodies of code that generalize to wide ranges of applications.

Still, we’re not all writing STL core classes every day. Sure. Write code so good it doesn’t need to be read. Write code so good that people want to read it. And write code that, when read, is welcoming, comprehensible, and considerate of others or yourself in the future.

Saying the first thing shouldn’t mean unsaying the other things… Something our author may learn over time.

Re:Good code is rarely read by aaronbrethorst on Saturday June 15, 2024 @12:58PM (#40690956)
I would argue that lots of useful code is an utter dumpster fire internally. That doesn't mean we shouldn't strive to do better.

        Useful
          |
          |
    Bad-------Good
          |
          |
      Not Useful
Re:Good code is rarely read by eyelidlessness on Saturday June 15, 2024 @05:10PM (#40692721)
There’s probably a time axis that comes into play, at least for a large number of projects. Bad code which is immediately useful, even indispensable, can decline in utility fairly sharply the parameters which determine its usefulness change faster than it can be adapted to meet those needs or goals.
Re:Good code is rarely read by aaronbrethorst on Saturday June 15, 2024 @05:19PM (#40692789)
There's definitely a time axis that comes into play. I'd say that all tech debt should be (but probably isn't always) in that top left quadrant. Like they say, good/fast/cheap - pick two (if you're lucky).
Re:Good code is rarely read by earnesti on Saturday June 15, 2024 @06:05PM (#40693038)
Not useful code is always bad, because you never had to write it. It is just a waste.
Re:Good code is rarely read by aaronbrethorst on Saturday June 15, 2024 @08:00PM (#40693587)
Requirements change. projects pivot. Yesterday’s must have feature is tomorrow’s deleted code
Re:Good code is rarely read by bayindirh on Saturday June 15, 2024 @10:49AM (#40690155)
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 by gravypod on Saturday June 15, 2024 @10:59AM (#40690214)
> 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 believe this varies wildly programmer to programmer. I'm often diving into code and reading that when debugging. I've done this with many code bases. It may be debatable if any of them are "good".

Re:Good code is rarely read by bayindirh on Saturday June 15, 2024 @01:30PM (#40691180)
People's quality bar differs in height, that's true, but I want to raise one example: https://rclone.org/install.sh

Which is readable, understandable and exceptionally good at what it does for 200 line bash script.

So, there's good code out there.

Re:Good code is rarely read by pydry on Saturday June 15, 2024 @10:50AM (#40690160)
Most essays about good code seem to end up being tautological.

The good ones dont.

Re:Good code is rarely read by ModernMech on Saturday June 15, 2024 @10:47AM (#40690147)
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 by Sakos on Saturday June 15, 2024 @04:35PM (#40692521)
Is that possible? I'm not sure if I've ever read code like that before, but maybe that's just me.
Re:Good code is rarely read by petermcneeley on Saturday June 15, 2024 @04:35PM (#40692525)
I think you are not reasoning correctly here

Adding features to a code means it was incomplete. Misunderstanding input/output usually means it is poorly documented or lacked a good API. A good API works at the surface (in/out) and not in the volume.

Really good code solves a problem completely. I have worked with such code and yes almost nobody ever goes into this code (and makes changes).

Re:Good code is rarely read by wavemode on Saturday June 15, 2024 @04:49PM (#40692604)
> Adding features to a code means it was incomplete

In practice this isn't true. The code may have been perfect and complete according to the business requirements of 1 month ago. But the business requirements of 1 month ago and today are often completely different.

Re:Good code is rarely read by petermcneeley on Saturday June 15, 2024 @05:52PM (#40692960)
This falls outside of my experience. I am systems or "backend".
Re:Good code is rarely read by xboxnolifes on Saturday June 15, 2024 @08:08PM (#40693631)
I'm not familiar with many systems or backend software that are still actively used, multiple decades old, and not still receiving updates. If it's not even a decade old, it's not old enough to say requirements won't change.
Re:Good code is rarely read by phito on Sunday June 16, 2024 @04:52AM (#40695652)
How does being a backend engineer makes you safe from business requirements changes? It doesn't add up to me.
Re:Good code is rarely read by cjblomqvist on Saturday June 15, 2024 @05:26PM (#40692828)
I thought you extended, not edit, really good code to achieve that
Re:Good code is rarely read by x0x0 on Saturday June 15, 2024 @04:49PM (#40692602)
> Adding features to a code means it was incomplete.

That definitely implies code can't be good if needs change, which makes no sense to me.

Re:Good code is rarely read by tanseydavid on Saturday June 15, 2024 @07:14PM (#40693398)
Missing feature implies an error at the Requirements level.

This does not impact readability or the idea of "good code" in my opinion.

You could have an application that is missing features which still contains examples of "good code". Learning about "good code" by reading the source code of this application won't really give any direct hints of missing features...the granularity is different.

Re:Good code is rarely read by philosopher1234 on Saturday June 15, 2024 @10:04PM (#40694162)
Why does it imply an error? The world changes, is that an error? You built around one reality, and reality changed. No one can predict the future.
Re:Good code is rarely read by mewpmewp2 on Sunday June 16, 2024 @01:05PM (#40698516)
What about changing features? E.g. a feature has to change 2 years down the line because certain laws are passed and this changes how the business logic should behave.
Re:Good code is rarely read by jacoblambda on Saturday June 15, 2024 @04:54PM (#40692620)
Adding features means it was incomplete. Good code can essentially always be built upon instead of modified.
Re:Good code is rarely read by oblio on Saturday June 15, 2024 @05:10PM (#40692723)
Laws change, business requirements change, network protocols/external APIs change, ...

Your approach is I guess valid for self contained algorithmic code, i.e. 0.000001% of code out there.

Re:Good code is rarely read by x0x0 on Saturday June 15, 2024 @05:06PM (#40692696)
But code can be complete and then become so-called incomplete because, again, needs change.

eg someone releases a new file format. You believe ffmpeg is bad code?

Re:Good code is rarely read by mewpmewp2 on Sunday June 16, 2024 @01:07PM (#40698529)
In that case you could argue that you would be just writing new code to write a handle for that file format.

In ffmpeg case I assume this is how it would be.

Re:Good code is rarely read by exe34 on Saturday June 15, 2024 @04:59PM (#40692648)
is "building upon" different from "adding features", in this new terminology?
Re:Good code is rarely read by aaronbrethorst on Saturday June 15, 2024 @04:56PM (#40692628)
Let me guess, you work on game engines?
Re:Good code is rarely read by petermcneeley on Saturday June 15, 2024 @05:34PM (#40692890)
I have but I dont currently. I am guessing the implication is that game engines have good code while other subsectors do not.
[dead]
Re:Good code is rarely read by petermcneeley on Saturday June 15, 2024 @05:36PM (#40692895)
Re:Good code is rarely read by nsinreal on Sunday June 16, 2024 @05:26AM (#40695788)
Well, what's wrong with code being incomplete at some point of time?

Is it not waterfall enough? Is it too much learning from customers? Is it too small PRs of duration less than 1-6 months? Is it not enough premature optimization?

[dead]
Re:Good code is rarely read by xwowsersx on Saturday June 15, 2024 @05:33PM (#40692878)
You are being a pedant. "Good" can describe anything that meets high standards or performs well in its context, e.g. as 'good game' or 'good weather.'

Your excessive focus on minor linguistic nuances is counterproductive. It's more important to understand the overall message than to get bogged down by trivialities, which everyone here seems to be able to do — except you.

Moreover, by repeatedly correcting language, you give off an 'I'm smarter than you' vibe, which isn't conducive to a productive conversation.

Re:Good code is rarely read by eyelidlessness on Saturday June 15, 2024 @05:04PM (#40692684)
In case it isn’t obvious, I’m reasonably confident that most everyone else is discussing “good” as an assessment of quality, not morality.

There are actually aspects of morality which might be discussed, but I generally don’t think it’s the topic at hand.

Re:Good code is rarely read by aaronbrethorst on Saturday June 15, 2024 @04:54PM (#40692623)
Books and movies have no morals and so they cannot be good or bad.
Re:Good code is rarely read by frapaconi on Saturday June 15, 2024 @05:00PM (#40692660)
Precisely! Well, I suppose Arnold runs bad code in Terminator. Well, I suppose suppose it might be good code according to Skynet.
[dead]
Re:Good code is rarely read by aaronbrethorst on Saturday June 15, 2024 @05:13PM (#40692748)
I know this can be hard to accept, but language is fluid and words have many different ways of being used.