Hacker News new | ask | show | jobs
by mrguyorama 3051 days ago
"Self documenting code" often isn't, in my experience
1 comments

On a scale from x to ListOfSinglePeopleWhoHasADogButNoCar I'd say that "self documenting" code tend to be quite a lot more so than some of the alternatives I've seen.

However, if someone claims to write self documenting code, and by that think it's enough to have long variable names and skip comments, then I can understand the sentiment above coming into existance.

In "identifiers are comments" paradigm the goal isn't only to just skip comments, but also to structure the code in a way so that it's as clear as possible what it does and why. This helps much more than a long comment block hidden somewhere in a big ball of spaghetti code.

Comments aren't a panacea either, as they take effort to write in a helpful way, often only occurs once (so you'd have to find the place where the purpose of x is defined) and of course, often are some level of wrong/outdated in relation to the purpose/function of the code.

Sometimes, it's not possible to write the code in a way that is clear, this could be for compatibility reasons or performance reasons. That is when comments really come into their light.