Yeah but there's a fundamental difference between something like tests that can be checked automatically and comments, that have to be checked manually. Because of this, it can be assumed that comments will eventually go out of date.
Good PR review from a skilled and more senior developer catches these things, most of the time.
Just like how tests catch functionality issues , most of the time — bugs still exist in tested software, because people make incorrect assumptions about how/what to test, or implement the test wrong.
> it can be assumed that comments will eventually go out of date.
Don’t make assumptions. That’s just a lazy excuse for not trying.
The same thing could be said for tests
> it can be assumed that tests will eventually go out of date
So why should we bother updating tests? They’re just going to go out of date?!!
Because it makes the codebase easier to work with for someone brand new.
Same as comments.
Pay down the debt for the next person. The next person could even be you in a year’s time after working in a completely different project for 9 months.
Tests only test functionality, they don't test business context. Comments explain business context.
For example, "we have this conditional here because Business needs this requirement (...) satisfied for this customer"
Your comment can test the logic works correctly. But someone coming in, without the comment, will say "why are we doing this? Is this a bug or intentional? Is the test bugged, too?"
Now, they'll see it's intentional and understand what constraints the code was written under. Your test can't send a slack message to a business analyst and ask them if your understanding is correct. The original dev does that, and then leaves a comment explaining the "why".
All software is built by humans in some way. All software has mistakes.
Perfection is an impossible goal.