5 ms·
So even if comments are flawlessly updated they are not a silver bullet. Not everyone are good at explaining confusing concepts in plain English so worst case y
by mnsc 2y ago
So even if comments are flawlessly updated they are not a silver bullet. Not everyone are good at explaining confusing concepts in plain English so worst case you have confusing code and a comment that is 90% accurate but describe one detail in a way that doesn't really match what the code says. This will make you question if you have understood what the code does and it will take time and effort to convince yourself that code is in fact deterministic and unsurprising.
(but most often the comment is is just not updated or updated along with the code but without full understanding, which is what caused the bug that is the reason you are looking at the code in question)
- rtpg 2y agoAn outdated comment is still a datapoint! Including if the comment was wrong when it was first written! We live in a world with version history, repositories with change requests, communications… code comments are a part of that ecosystem. A comment that is outright incorrect at inception is still valuable even if it is at least an attempt by the writer to describe their internal understanding of things.
- more-coffee 2y agoThis. I have argued with plenty of developers on why comments are useful, and the counter arguments are always the same. I believe it boils down to a lack of foresight. At some point in time, someone is going to revisit your code, and even just a small `// Sorry this is awful, we have to X but this was difficult because of Y` will go a long way. While I (try to) have very fluid opinions in all aspects of programming, the usefulness of comments is not something I (think!) I'll ever budge on. :)
- temporallobe 2y ago> // Sorry this is awful, we have to X but this was difficult because of Y You don’t know how many times I’ve seen this with a cute little GitLens inline message of “Brian Smith, 10 years ago”. If Brian couldn’t figure it out 10 years ago, I’m not likely going to attempt it either, especially if it has been working for 10 years.
- larsrc 2y agoBut knowing what Brian was considering at the time is useful, both due avoiding redoing that and for realising that some constraints may have been lifted.
- xnx 2y agoWe should call them code clues
- temporallobe 2y agoIt just occurred to me that perhaps this is where AI might prove useful. Functions could have some kind of annotation that triggers AI to analyze the function and explain it plain language when you do something like hover over the function name in the IDE, or, you can have a prompt where you can interact with that piece of code and ask it questions. Obviously this would mean developer-written comments would be less likely to make it into the commit history, but it might be better than nothing, especially in older codebases where the original developer(s) are long gone. Maybe this already exists, but I’m too lazy to research that right now.
- bccdee 2y agoBut then could you trust it not to hallucinate functionality that doesn't exist? Seems as risky as out-of-date comments, if not more What I'd really like is an AI linter than noticed if you've changed some functionality referenced in a comment without updating that comment. Then, the worst-case scenario is that it doesn't notice, and we're back where we started.
- buttercraft 2y agoWhat if you don't know that the comment is wrong?
- lexicality 2y agoIMO the only thing you can assume is that the person who wrote the comment wasn't actively trying to deceive you. You should treat all documentation, comments, function names, commit messages etc with a healthy dose of scepticism because no one truly has a strong grip on reality.
- rtpg 2y agoRight, unlike code (which does what it does, even if that isn't what the writer meant) there's no real feedback loop for comments. Still worth internalizing the info based on that IMO. "This does X" as a comment when it in fact does Y in condition Z means that the probability you are looking at a bug goes up a bit! Without the comment you might not be able to identify that Y is not intentional. Maybe Y is intentional! In which case the comment that "this is intentional" is helpful. Perhaps the intentionality is also incorrect, and that's yet another data point! Fairly rare for there to be negative value in comments.
- michaelcampbell 2y ago> So even if comments are flawlessly updated they are not a silver bullet. This "has to be perfect in perpetuity or it is of no value" mentality I don't find helpful. Be kind to FutureDev. Comment the weird "why"s. If you need to change it later, adjust the comment.
- bccdee 2y agoYeah: "what if this code becomes tech debt later" applies to everything, not just comments. It's a tradeoff. The best thing you can do to avoid creating debt for later maintainers is to write code that's easy to delete, and adding comments helps with that.
- mnsc 2y agoI don't think comments need to be perfect to have value. My point was that if a certain piece of code is solving a particularly confusing problem in the domain, explaining it in a comment doesn't _necessarily_ mean the code will be less confusing to future dev if the current developer is not able to capture the issue in plain English. Future dev would be happier I think with putting more effort into refactoring and making the code more readable and clear. When that fails, a "here be dragons" comment is valuable.
- MichaelZuo 2y agoThey can write a very long comment explaining why it is confusing them in X, Y, Z vague ways. Or even multilingual comments if they have better writing skills in another lanaguage. And even if they don’t know themselves why they are confused, they can still describe how they are confused.
- deleted 2y ago[deleted]
- stouset 2y agoAnd any attempt whatsoever is some improvement over doing nothing and wishing luck to the next guy.
- Zondartul 2y agoComments that explain the intent, rather than implementation, are the more useful kind. And when intent doesn't match the actual code, that's a good hint - it might be why the code doesn't work.
- hedora 2y agoIf a developer can’t write intelligible comments or straightforward code, then I’d argue they should find another job.
- pixl97 2y agoI mean it's easy to say silly things like this, but in reality most developers suck in one way or another. In addition companies don't seem to give a shit about straightforward code, they want LOC per day and the cheapest price possible which leads to tons of crap code.
- hallway_monitor 2y agoEach person has their own strengths, but a worthwhile team member should be able to meet minimum requirements of readability and comments. This can be enforced through team agreements and peer review. Your second point is really the crux of business in a lot of ways. The balance of quality versus quantity. Cost versus value. Long-term versus short term gains. I’m sure there are situations where ruthlessly prioritizing short term profit through low cost code is indeed the optimal solution. For those of us who love to craft high-quality code, the trick is finding the companies where it is understood and agreed that long-term value from high-quality code is worth the upfront investment and, more importantly, where they have the cash to make that investment.
- pixl97 2y ago>I’m sure there are situations where ruthlessly prioritizing short term profit through low cost code is indeed the optimal solution This is mostly how large publicly traded corps work, unless they are ran by programmers that want great applications or are required by law, they tend to write a lot of crap.
- mlloyd 2y ago>In addition companies don't seem to give a shit about straightforward code, they want LOC per day and the cheapest price possible which leads to tons of crap code. Companies don't care about LOC, they care about solving problems. 30 LOC or 30k LOC doesn't matter much MOST of the time. They're just after a solution that puts the problem to rest.