Live data from Hacker News

Good code is like a love letter to the next developer who will maintain it

addyosmani.com

81–90 of 274 posts

Re: Good code is like a love letter to the next developer who will maintain it

#81
post #15

In my opinion, good code is like a Brita filter. It does its job, will one day need to be replaced, and it should be easy to replace. More importantly: metaphors are not a healthy way to understand an idea. Ideas are more nuanced than a metaphor could possibly account for. Abstaining from metaphors might not make for a catchy headline though.

Metaphors are a fine way to understand an idea if one accepts that their purpose is to leverage an existing understanding of something, and that they're lossy. So I guess my issue with your comment's second half is that I don't think metaphors are being used as a shortcut to a full and complete understanding of a topic. They're an aid and I think that is mostly how they're used, IME. I don't think they should be written off.

Re: Good code is like a love letter to the next developer who will maintain it

#83

As someone who has gone back and read my old code as well as a lot of others old code, there is no such thing as good code. IMHO, the problem is one of cultural context which is often not shared between generations of coders. Languages and best practices can change so violently that best-practices one decade are often anti-patterns in the next. As a codebase outlives its best-practices, do you stick with them and ext…

I disagree. Good code is code that is indistinguishable in style and convention from all adjacent code. I always advise juniors two things:

1) your code will be written once but read a thousand times

2) if you want to make your mark with style and convention start an OSS project of your own, otherwise make your mark through the simplicity and elegance of your logic, not the way your code contrasts from the code base.

Re: Good code is like a love letter to the next developer who will maintain it

#84

As someone who has gone back and read my old code as well as a lot of others old code, there is no such thing as good code. IMHO, the problem is one of cultural context which is often not shared between generations of coders. Languages and best practices can change so violently that best-practices one decade are often anti-patterns in the next. As a codebase outlives its best-practices, do you stick with them and ext…

i don't agree with this take at all.

good code solves the problem at hand. good code is as simple as possible. good code is testable and tested. good code is minimal. good code is performant. good code is maintainable. good code is understandable.

yes it matters somewhat that you have some consistency of the way you code. that's a secondary thing

Re: Good code is like a love letter to the next developer who will maintain it

#85
post #12

Sorry next developer, I'm on a tight deadline, used to love this craft, now I just do what the product people tell me to get a nice paycheck.

Sorry future me, I'm on a tight deadline. If I spent an extra two hours making this better now, you wouldn't have to spend two days fixing these problems. You're probably still on a tight deadline.

Re: Good code is like a love letter to the next developer who will maintain it

#86

As someone who has gone back and read my old code as well as a lot of others old code, there is no such thing as good code. IMHO, the problem is one of cultural context which is often not shared between generations of coders. Languages and best practices can change so violently that best-practices one decade are often anti-patterns in the next. As a codebase outlives its best-practices, do you stick with them and ext…

> there is no such thing as good code. nor is there such a thing as a good love letter

well there probably are a few, but most love letters you wouldn't want to read if it wasn't for you - and even then maybe not.

Re: Good code is like a love letter to the next developer who will maintain it

#87

As someone who has gone back and read my old code as well as a lot of others old code, there is no such thing as good code. IMHO, the problem is one of cultural context which is often not shared between generations of coders. Languages and best practices can change so violently that best-practices one decade are often anti-patterns in the next. As a codebase outlives its best-practices, do you stick with them and ext…

> there is no such thing as good code

But do you think there is bad code? If so, I'll give you the official definition of good code: code that isn't bad code.

Re: Good code is like a love letter to the next developer who will maintain it

#88
post #32

Good code is not like art, such as good books or paintings. No matter the quality of your code, if the product or service is not a good market fit. It will be retired. No one will stumble upon it or pick it up after it's gone. Knowing this, the only reason for putting effort into it is to make it easier for myself.

> No matter the quality of your code, if the product or service is not a good market fit. It will be retired. No one will stumble upon it or pick it up after it's gone. This applies to artistic endevours like books and paintings as well (especially those two, since markets for them are very oversaturated). Your technique might be masterful, but if your art doesn't align with current trends (along with a number of oth…

Yes I thought about that, I was thinking in the sense that someone in the future might actually stumble upon a painting or a book. They won't with proprietary forgotten code.

Re: Good code is like a love letter to the next developer who will maintain it

#89
post #32

Good code is not like art, such as good books or paintings. No matter the quality of your code, if the product or service is not a good market fit. It will be retired. No one will stumble upon it or pick it up after it's gone. Knowing this, the only reason for putting effort into it is to make it easier for myself.

The two aren’t always mutually exclusive, you might be writing code for a good market fit that stands the test of time and needs maintaining. The times you appreciate it are actually when you open something and it’s nice and easy to change and you realise you were the one who wrote it. But real developer happiness comes when you have the same experience and someone else wrote it.

Indeed, I'm just trying to highlight your efforts as an 'artist' might be wasted.

I recently worked on a project with some seriously clean code. My job? Shut it down. This made me sad.

Re: Good code is like a love letter to the next developer who will maintain it

#90
post #70

As someone who has gone back and read my old code as well as a lot of others old code, there is no such thing as good code. IMHO, the problem is one of cultural context which is often not shared between generations of coders. Languages and best practices can change so violently that best-practices one decade are often anti-patterns in the next. As a codebase outlives its best-practices, do you stick with them and ext…

> there is no such thing as good code definitely not true. this is good code: https://github.com/torvalds/linux/blob/master/fs/file.c this is good code: https://github.com/golang/go/blob/master/src/strconv/atoc.go its formatted, commented, direct. the fact that you struggle with writing time tested code does not mean that everyone does.

By linking to those examples you confirmed the point you were trying to refute.

From my personal perspective this is mediocre code at best.

It’s written in an unsafe language.

Littered with macros, which in C are not hygienic and are land mines in waiting.

Constants defined with lowercase and not actually marked as const.

Double underscores everywhere, which are the bad alternative to namespaces seen in weak languages like C.

WTF does “BITBIT_NR(nr)” do!? Does it “bit” the “bits”? What is NR? Is it a “number”? Then why not use “n” and drop it from the macro name?

Abbreviations everywhere: ofdr, nfdt, fds, fs, etc…

Then there is a long-winded explanation of how they pack bits into an array of longs. Okay, why not make this a reusable module of code? Because C is a weak language, or because the Linux kernel is spaghetti with a dozen implementations of bit maps?

    \*
     * Note that this can drive nr *below* what we had passed if sysctl_nr_open
     * had been set lower between the check in expand_files() and here.  Deal
     * with that in caller, it's cheaper that way.
Huuuurk.

Sorry… did I just see a data race just casually commented as “okay because it is faster if it’s horrifically unsafe?

Yes? No? Maybe?

Do you even know?

Post reply on HN