this post was submitted on 20 Jul 2025
658 points (99.0% liked)
HistoryPorn
6980 readers
633 users here now
If you would like to become a mod in this community, kindly PM the mod.
HistoryPorn is for photographs (or, if it can be found, film) of the past, recent or distant! Give us a little snapshot of history!
Rules
- Be respectful and inclusive.
- No harassment, hate speech, or trolling.
- Foster a continuous learning environment.
- No genocide or atrocity denialism.
Pictures of old artifacts and museum pieces should go to History Artifacts
Illustrations and paintings should go to History Illustrations
Related Communities:
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Fla already explained the rough logic behind it, but I also think a big part of it is that people have a habit of approaching advice like this too dogmatically. For example, guidance that says "commenting your code is not a substitute for sensible structure and variable names", and someone may read that and go "I shouldn't use comments, got it". Certainly I have seen (and written) code that overuses comments in a manner that the average comment has pretty low information value — for me, this was because I was inexperienced at writing code other people would use, and comments were things that I felt I should do, without properly understanding how to do it. Like if there's a line that says
a += b
, I don't need a comment that says "# adds b to a". That misses the point of comments entirely, and would make important comments harder to see, and the code harder to understand.Another area where I often see this overly rigid mindset is the acronym "DRY", which means "don't repeat yourself." It's a decent principle, and it's helped me to identify larger structural problems in my code before. However, some people take it to an extreme and treat it as an absolute, inviolable law, rather than a principle. In some circumstances, repeating oneself would improve the overall code.
If I had to choose between code that had sensible variables and structure, but no comments, and code that was opaque but heavily commented, I'd probably choose the former. However, in practice, it's a "why not both" situation. It's less about the comments than how well they're used, and identifying comments as a code smell may be an attempt to get people to approach code readability slightly differently and using comments more wisely.
That makes sense. I've certainly been guilty of excessively DRYing my code. On one hand, it's a fun little puzzle to work on. On the other hand, it's been making it very hard to quickly iterate, and that's especially bad for research code.
It only nakes sense to apply DRY principles when you find you keep having to copy paste the same code to muliple locations on your codebase, and its reasonably clear it will never diverge from eachother. In other words, apply as needed to maintain development velocity (and in turn stability).