5 ms·
Or you can write tests for every single not there case. Just bringing it up, I usually write lots more comments than tests. I also encourage my teammates to add
by pmoleri 5y ago
Or you can write tests for every single not there case. Just bringing it up, I usually write lots more comments than tests. I also encourage my teammates to add comments. The problem is when one can't really explain why the simpler approach didn't work. That requires more research just to write the comment, but I think it pays off really quick.
- gizmo686 5y ago> The problem is when one can't really explain why the simpler approach didn't work. Another benifit I have found is that in studying the problem to understand why the simpler approach doesn't work, you find out that it can actually work.
- benrbray 5y agoTests are useful, but the big reason that comments are useful is that they are co-located with the relevant code. At the moment, I don't know of any tools that allow you to 1) specify which lines of code are directly relevant to a particular test case, even when the surrounding code changes and 2) see a list of test cases related to the currently highlighted line. I'm sure it would be possible to build such a tool, but the complexity is quite substantial compared to a simple comment or two. If you really want to go the full-test-coverage route it makes a lot more sense to focus that energy on pure/immutable/statically-verified programming rather than some finicky test cases that add substantial maintenance cost to the code.
- dstick 5y agoExactly. And then the question remains: why? Why hate comments so much? I never got that
- rwallace 5y agoI would conjecture that it has two components: 1. Ancestral memory of programming in languages like assembly or early Fortran where your code was going to be spaghetti because the language was capable of little else, so it had to be drenched in comments that would be unnecessary in a better language. 2. Overreaction to personal memory of overzealous professors who demanded assignments be drenched in excessive comments.
- benrbray 5y agoRelated to #2, I'm still recovering from high school AP English. We had to meet quotas for a certain number of underlines / notes written in the margin per page. For the better part of a decade I haven't been able to pick up fiction without the feeling that I'm working through a textbook.
- cush 5y agoUntil the code changes, then the comments are usually worse than nothing
- AlotOfReading 5y agoI've seen this counterpoint brought up many times before, but I'm struggling to think of the last time I experienced it. Is it really a common problem for you?
- cush 5y agoYes, the issue isn't that most comments are inaccurate, it's that the inaccurate ones are so costly. When the comment doesn't match the code, it makes you question the code and the intent. 90% of the time, comments are accurate or just redundant (the code is descriptive enough), but that 10% of the time when the comments says A and B is happening, I end up chasing down whoever or digging through changelogs and tickets to find the comment wasn't updated.
- taneq 5y agoThen you fire the coder who changed the code without updating the comments?
- kwhitefoot 5y agoThat's a waste. Just train them better.
- cush 5y agoMost code doesn't need comments.
- benrbray 5y agoNo. Comments are like a parity check. If the comments don't match the code, then you know that either: 1) The comments are correct, but the code is wrong. This is a bug. 2) The comments are wrong, but the code is correct. This is equally a bug. Whoever makes the change has an obligation to describe their changes with a comment. Code with no comments? Could be right, could be wrong, who knows?
- OJFord 5y ago> Tests are useful, but the big reason that comments are useful is that they are co-located with the relevant code. That's a not-often-talked-about (that I see anyway?) thing I really like about rust - I don't get to use it much, but when I do I think having 'doc tests' alongside comments heading a function and 'module tests' at the bottom of the same file is great.