Live data from Hacker News

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

addyosmani.com

111–120 of 274 posts

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

#111

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…

If there is no such thing as good code, why does it spark so much discussion? Why care at all?

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

#112

Earlier quoted context omitted.

I think about this all the time when it comes to evolving systems. I work on a programming language, and these tensions are core to my job. In the context of a language, I think it can be: * Modern, where the language's features and idioms reflect the best way we know to write good, clean code today. * Compatible, where code written in the language years ago continues to run the same as when first written. * Simple,…

You mean your work on Dart at Google or are you working on a new programming language right now? If it's the latter, I need more info please!

Dart, but this is true of my various hobby languages too (though those have the delicious advantage of almost no users to worry about breaking).

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

#114

Earlier quoted context omitted.

Metaphors are also ways of communicating ideas. A good metaphor is as simple or as complicated as it needs to be in illustrating a new concept

Problems arise as soon as you (ab)use a metaphor (used to explain a higher level/adjacent problem) to explain concepts it was never meant to model. Example: Array of items as a shopping cart: how do you efficiently remove an item from the array (as you can from a shopping cart)?

There's always a possibility that a bad metaphor can be made, but this doesn't mean that metaphors themselves are bad. They require at least some consideration in order to communicate and relate the relevant details of something to another thing. It would be like criticizing multiplication because sometimes people forget to carry extra values

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

#115
post #70

Earlier quoted context omitted.

> 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 language…

I bet you a nickel that -if you're a working programmer- most of the functions that you write don't check __every__ possible thing that could go wrong, but -instead- have some assumptions about validations that the caller must run before calling them (e.g. "My callers will hand me well-formed XML"), and impose some constraints on the shape and range of the data that they return to their caller (e.g. "Callers must be prepared to handle a graph that contains cycles.").

> ...did I just see a data race...

You did see a data race.

That race is pretty clearly unavoidable, as it would be triggered by a sysadmin setting the value of a particular sysctl knob "low enough" in between the check mentioned in another function in the chain of function calls that this function is part of being run and the commented code being run.

(You can tell that this function part of a chain of function calls because that comment refers to a check in a function that is not called by the function that contains the comment.)

> ...okay because it is faster if it’s horrifically unsafe...

I mean, here's the call site of the "objectionable" function and the site at which the issue gets detected: https://github.com/torvalds/linux/blob/master/fs/file.c#L174...>. At both ends, there's a comment that says "Hey, it's faster to do this check here, rather than over there.".

It's clear that the folks who worked on this code were concerned about the performance, and had discovered that relying on callers to discover if that race had resulted in them getting a smaller allocation than they wanted was needed.

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

#116

Precisely why I also create READMEs in top-level directories. I'm not going to remember how to structure queries for my API a year from now. Future me will always appreciate how considerate present me was.

> Future me I like this term a lot more than "the next developer."

You know how on a plane the flight attendant tells you to make sure your oxygen mask is on before helping others (in case of emergency)? I think of coding well and documentation the same way.

How can I help you without first helping myself?

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

#117
post #98
post #62

Earlier quoted context omitted.

The craft is not the code, but the product. You can have beautiful code and garbage product, and great code and a garbage product. If your PM is pushing bad products, that's on them. Your job is to deliver good product, not good code.

That’s not a great way to look at it. You can be passionate about the craft and not passionate about the product. You can usually find interesting problems relating to craftsmanship even when doing things you’re not thrilled to do. Let’s be honest: sometimes you’re not “changing the world” like many founders like to think, just building yet another shopping cart. If you lose love for your craft there’s no product tha…

Well said. I am certainly not in this game because I love building forms. Mastering my tools of choice grants me satisfaction. It's hard to find a place working on a product that is truly interesting, but fortunately at least, finding a place working with tools I like is easier.

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

#118
post #109

Earlier quoted context omitted.

I think I just fell in love with you. Finally a sane person Honestly, I never understood why so many developers abbreviate function names or variables. Is it so much pain to type abc for auto completion? Why not simply name fd file_descriptor? Short names are a mental barrier and a level of abstraction that can easily be avoided.

Short names actually help with readability when they are commonly used. It's a lot quicker to go over the code when you don't need to read as much, similar to how one would write something like x+y=z in math instead of putting descriptive name for each variable in each step or using things "1€/kg" instead of "one euro per kilogram" (or let alone including kilogram's definition from SI standard).

Despite this, mathematical proofs still use a bunch of plain words to define things. In a programming context, if one has an “user” from the database, “user” is usually a better name than “u”.

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

#120

Developers love to debate about these things, but everything has been said already. I've noticed that the better the developers, the less they engage about these topics.

Developers who enjoy discussing what makes code good are worse developers than those who don't enjoy discussing it? Is that the thrust of your comment?
Post reply on HN