News for hackers. Stuff that matters.
Re:Ask HN: If your code no longer makes sense to you, do you... by kazinator on Saturday July 01, 2023 @09:02PM (#36557083)
If your old code doesn't make sense, you better sit down, engage the code and figure it out.

Otherwise you have to concede that you're getting dumber. Someone better than you wrote code you don't understand, and it happened to be your younger self.

Re:Ask HN: If your code no longer makes sense to you, do you... by thfuran on Saturday July 01, 2023 @10:33PM (#36557611)
If two people code up a solution to a problem and only one person can understand one of the solutions but everyone who looks at the other can understand it easily, who wrote the better solution?
Re:Ask HN: If your code no longer makes sense to you, do you... by kazinator on Sunday July 02, 2023 @12:08AM (#36558130)
The better solution is the one with fewer bugs, fewer dependencies and less resource use.

If the solutions are both correct and use the same approach, but one has managed to make it understandable, then that is better. Understandable beats obfuscated, all else being equal.

The solution that the programmers don't understand reveals a weakness in their analytic skills, though. The author could well be smarter or know more techniques, or both.

Re:Ask HN: If your code no longer makes sense to you, do you... by muzani on Sunday July 02, 2023 @01:27AM (#36558507)
It's easier to write code than it is to read code. That's why there's so much emphasis on documenting and why someone inevitably writes functions that already exist.
Re:Ask HN: If your code no longer makes sense to you, do you... by kazinator on Sunday July 02, 2023 @03:23AM (#36559126)
We simply cannot make this generalization. It is obviously false of other creative activity involving writing; it is not harder to read a novel than to write a novel, for instance. However, it's easy for someone to effortlessly spew stream-of-consciousness drivel into their blog, which is painful to read for someone else. It is more or less so with programs.

There is one way in which reading is absolutely harder that writing. Writing (a given revision of the code, or any other text) is only done once. Once you have written that, nobody else has to write that ever again.

Reading is not like that. Nobody can read it once, so that then nobody else has to read it. Everyone who needs to read it must do it for themselves; explanations and summaries given by others who have read it before only go so far. Even one individual must repeatedly read it in order to get it, after which he or she will forget it anyway with the passage of time. The code doesn't "stay read" the way it stays written; if you come back to it in 25 years, there is nothing to write (other than a new revision, but my point is no need to write the original revision). If you come back to reread something in 25 years, you might as well have never seen it before.