5 ms·
You can even tell that's ChatGPT rather than, say, Claude. Redundant obvious comments are a stylistic signature of their models.
by Mizza 2y ago
You can even tell that's ChatGPT rather than, say, Claude. Redundant obvious comments are a stylistic signature of their models.
- LoganDark 2y agoI wonder if they programmed that into them through RLHF, as a way of trying to teach the model that a preceding comment should be completed by whatever code is described by the comment
- soulofmischief 2y agoI make comments like this all the time because I write code for people to read, not robots. Well-commented code allows you to skim very quickly, and gives a sanity check, allowing others to ensure a line or block of code does what it is expected to do.
- kelnos 2y agoThat's not well-commented code, that's just noise. When you are calling a function named "read_csv()", you do not need to add a comment that says "Read the CSV file". These sorts of comments make code harder for humans to read. The hill that I will die on is that if you need to comment what your code is doing, your code is either a) bad and should be rewritten to be clearer, or b) the result of tricky, clever optimization that you needed to do after profiling. Comments should tell readers why you're doing something, when it's not obvious based on the code itself.
- soulofmischief 2y agoI agree that there should be "why" comments. Those are great to have in any codebase. However, that does not preclude descriptive comments. Obviously, the best way to make code self-documenting is to wrap logic in a method whose name clearly describes its intended function. For one-liners however this can lead to overabstraction, and leaving a "what" comment can be entirely appropriate if the engineer decides it is. This cult-like behavior of engineers who think that well-commented code is some sign of weakness or unprofessionalism is beyond silly. Absolutisms are a sign of a bad engineer, but I can give you the benefit of the doubt and not assume you're a bad engineer just because you employ such absolutist statements and use erroneously use them to judge code by oversimplified metrics instead of relying on deeper analysis.
- cactacea 2y agoEvery word of the comment is in the code except "the". That level of redundancy is always bad. Yes, always.
- soulofmischief 2y agoA well-placed comment serves as an anchor for the eye when skimming large amounts of code, and provides a sanity check. This is something you would come to appreciate when working in certain environments. Does this mean every line of code needs an accompanying comment? No, that is absurd. But what's also absurd is the amount of judgement and unwarranted extrapolation over this particular bit of code, and the general defensiveness which most people in this thread seem to be engaging in. I leave comments like this sometimes if I think it helps increase code clarity.
- paulyy_y 2y ago"Absolutisms are a sign of a bad engineer" Oh the tasty irony.
- soulofmischief 2y agoI didn't say always. I made a general statement and avoided absolutist terms. "Are" is not an absolutist term if you charitably interpret my comment and I'm happy to clarify if you need it, however I don't need to append every comment with a disclaimer so that people like you don't respond with meaningless criticism towards some straw man. Please review the Hacker News guidelines, especially this excerpt: > Please respond to the strongest plausible interpretation of what someone says, not a weaker one that's easier to criticize. Assume good faith.
- UncleMeat 2y agoThis is a bad comment. It adds nothing to clarify anything, since the function in the line below is "read_csv." This would be a textbook example of a comment that is not useful to improve legibility by humans and it demonstrates a lack of expertise among the people who are currently dismantling our government.
- soulofmischief 2y agoI'm sorry, but a code comment does not demonstrate lack of expertise, although such a perspective certainly brings your own expertise into question. Perhaps we should all assume a little less?
- ttyprintk 2y agoI think it does, objectively. In a pull request, I’d comment: “You imported pandas with an abbreviation. You economize the variable name `df` instead of dataframe. Those anticipate a reader who already knows when to chose the read_csv method.”
- soulofmischief 2y agoIf you are in charge of reviewing someone's pull request and ensuring they adhere to specified company guidelines, you can do whatever your organization wants. Outside of that though, you lack the authority to tell programmers how many comments are too much. I too know how to write self-documenting code, but that doesn't mean your code should have no comments or shouldn't be liberally commented.
- ttyprintk 2y agoGP mentions that this is a textbook unnecessary comment and I would beware any textbook and professed expert that disagrees. Whether a LLM coding model demonstrates understanding of unnecessary comments might be interesting, as would any differentiation in quality if my prompt asked for more or fewer lines of comments.
- LoganDark 2y agoThis is not a case of "code for people to read". If you want that, maybe try literate programming[0]. I prefer in the case where the code is blindingly fucking obvious for there not to be an extra comment above it that adds no value whatsoever. I much prefer for comments to be about the theory of the code rather than to explain in a worse way what I can already clearly see simply by reading the code. In other words I much prefer comments about, say, why some particular data structure was chosen, over comments that only say shit like "create a new linked list". [0]: https://en.wikipedia.org/wiki/Literate_programming https://en.wikipedia.org/wiki/Literate_programming
- soulofmischief 2y agoHow about we don't tell other people how to code? It's one thing to make suggestions, it's another to make demands. I've been doing this for a long time and I can code laps around most people. I also like well-commented code that allows me to quickly skim code and check it for correctness. You can have your preferences all you want and that's great, but when you start passing irrational judgement about the value of someone's code just because it's liberally commented, your perspective becomes less respectable.
- LoganDark 2y ago> How about we don't tell other people how to code? It's one thing to make suggestions, it's another to make demands. I've been doing this for a long time and I can code laps around most people. I also like well-commented code that allows me to quickly skim code and check it for correctness. I'm sorry, that was not intended to be received as a demand, I edited my comment to hopefully clarify. > You can have your preferences all you want and that's great, but when you start passing irrational judgement about the value of someone's code just because it's liberally commented, your perspective becomes less respectable. I didn't say anything about the value of your or anyone's code other than that obvious comments don't add any to me. (I do tend to find it funny when a comment manages to obviously contradict the code that it's about, but here that's not the case.) My point was more that comments are more useful to me when they're non-obvious. See, again, the data structure example.
- meindnoch 2y ago// This is my reply: No. You have "well-commented code" completely backwards. This is not it. // This is the end of my reply.
- soulofmischief 2y agoYes, we can take anything to the extreme and hyperbolize in order to prove a point, but that doesn't really add anything useful to the discussion.
- rectang 2y agoA long time ago I picked up the habit of "coding in commented paragraphs": https://www.perl.com/pub/2005/07/14/bestpractices.html/#7-code-in-commented-paragraphs https://www.perl.com/pub/2005/07/14/bestpractices.html/#7-co... This style allows me to scan only natural language comments, generally rendered in a distinct highlight color, to get a high-level view of what the code does. My colleagues have rarely followed the same idiom, but my code has been well-regarded everywhere I've been. When you do this, there are occasionally times where you wind up with a single line that isn't grouped with the others, and to be consistent the easiest thing is to insert a comment like the one that started this thread. However, I've adapted this style over the years to avoid any hint of redundancy because some people feel so strongly that they will fixate on it and decide you're a terrible engineer for this one tiny detail. It's easier just to work around them.
- baobabKoodaa 2y agoI get redundant obvious comments from Claude Sonnet 3.5 and 3.7 all the time.
- geon 2y agoThat would be expected of generative predictive ai. The comments that are most likely to correlate strongly with the code are the useless redundant ones.