r/programming • u/theusualguy512 • Sep 26 '20
Found these comments by a developer inside the Windows Media Player source code leaked with the WinXP files yesterday, sort of hilarious
https://pastebin.com/PTLeWhc2
5.0k
Upvotes
r/programming • u/theusualguy512 • Sep 26 '20
39
u/Mourningblade Sep 26 '20
The good form of this is:
Code may not contain any comments describing what it is doing unless it is heavy low-level optimization. Short function documentation is fine (longer for core library routines).
Your reviewer must be able to read the code and understand what it is doing.
Your reviewer must be confident that they could understand and modify your code after being woken up at 2 AM after a night of drinking.
This encourages simple code that does what it says. It is difficult to program this way, but worth it.
As for WHY the code does what it does, that should be in both:
Commit description. If complicated enough, reference a design document.
Tests. If you're implementing business logic and it's not clear why one would want foo to happen when bar occurs, maintain a spec document that focuses on justifications. That "document" can be part of your acceptance testing, if it works for your company.
I work on a sizeable system that does the above strategy and it works well, even in onboarding new people. The code implements non-obvious business logic, but you can tell what the code is implementing, and you can read the business rules spec to understand why.
Unfortunately, some developers learn this strategy as:
No comments. The code should be clear about what is doing.
I can read my code just fine.
I'm not sure what your problem is.