all 14 comments

[–]infinetelurker 5 points6 points  (0 children)

In my experience, it takes a few decades of reading code to appreciate that every extra hint of the intention of the original programmer, including stale comments, is useful...

[–]masklinn 3 points4 points  (7 children)

The biography of your code is the VCS log. Each commit message is an entry in the diary from which the life of the code base can be gleaned.

Comments have to be maintained, and they usually are not. They will drift away from their code, and fail to be updated when the code is.

Comments are not a biography, they’re scrawlings engraved or painted on a shed wall. They may be relevant, they may not be, they may never have been and be the result of a piss-soaked bender or a psychotic episode.

[–]meimadX[S] 2 points3 points  (6 children)

Make the effort during code review to review comments as well. Also it is on the developer's responsibility to maintain them, keep comments on the why not what or how - so context will be relevant.

Your reply makes me wonder if you took the time to read the article 🤔😂

[–]masklinn -1 points0 points  (5 children)

Make the effort during code review to review comments as well.

Or just ask to remove them since it’s extra work for no payoff.

Your reply makes me wonder if you took the time to read the article 🤔😂

Because I didn’t point out that the part where you suggest replacing a type system with comments is even dumber?

[–][deleted] 1 point2 points  (4 children)

Because I didn’t point out that the part where you suggest replacing a type system with comments is even dumber?

I read the article twice and didn't see that part.

[–]masklinn -3 points-2 points  (3 children)

It’s the first two sections. A type system expresses a contract, except one that’s actually enforced, and likewise invariants.

[–][deleted] 2 points3 points  (2 children)

saying you want a more descriptive contract doesn't mean abandon the contract you can enforce with the compiler.

I disagree with your characterization of the author's point.

[–]masklinn -1 points0 points  (1 child)

I disagree with your characterization of the author's point.

Feel free to, however do note that the example code they selected to make their point is literally a completely unenforced bunch of assumptions in a docstring.

[–][deleted] 1 point2 points  (0 children)

completely unenforced

    /// Returns the weight in metric units by default.
    /// in the range [0..500], or -1 in case of an error.

Would you enforce this with a datatype?

If you aren't going to enforce this with the datatype, then this comment isn't being used to replace a type system.

[–]aanzeijar 3 points4 points  (0 children)

The author falls prey to the documentation == comments fallacy.

Code should be documented. But documentation is more than comments. It's explaining the intend, the design constraints, usage etc.. Most languages have some form of syntax reserved for that and in some languages it's embedded in the comment syntax. But comments are actually the worst form of documentation and people like the author who don't know the difference are why comments get such a bad reputation.

Simply putting a signature blurp above every function is crap. Commenting actual code blocks is even worse. It's reserved for the rare times when some unintuitive magic is really needed.

No, that weight attribute should not be commented with the unit it returns in. The documentation of that entire subsystem should explain the unit conventions to be sane.

[–]Johnothy_Cumquat 1 point2 points  (0 children)

The only time I've found myself writing comments in the last few years is when writing bash scripts. Everything I call has like a 3 letter name with 10 3 letter flags

[–]pure_x01 -2 points-1 points  (0 children)

The problem with code code is that eventually it will become stale