Why I refuse to give up code comments
I am old. I grew up in an age of cryptic Fortran and worse C code that absolutely required comments to be intelligible.<p>I currently teach two different courses that have opposite philosophies behind comments, AP Computer Science Principles in a charter high school and Level 7 Advanced Java Programming at the LEAGUE of Amazing Programmers, a private non-profit volunteer staffed coding school for middle and high schoolers.<p>The AP course stresses the importance of documentation, both block headers and in line comments. This (<a href="https:&#x2F;&#x2F;canvas.instructure.com&#x2F;courses&#x2F;943888&#x2F;pages&#x2F;adding-comments-or-commenting-on-programs" rel="nofollow">https:&#x2F;&#x2F;canvas.instructure.com&#x2F;courses&#x2F;943888&#x2F;pages&#x2F;adding-c...</a>) typical lesson is par for the course for most curriculums I&#x27;ve seen.<p>On the other hand our Level 7 curriculum notes say, &quot;Comments:
compensate for failure in expressing yourself in code;
- a comment is out of date as soon as it’s written
- maintenance nightmare
- code moves, comments don’t always follow
- if something is confusing or disorganized, clean it instead of commenting. cleaning &gt; commenting.<p>&quot;Exceptions: warning of consequences, explanation of intent, TODOs, copyright,  javadocs&quot;<p>But goes further to test students to use a shortcut in Eclipse to blindly remove all comments from Java code.<p>The example given in your explanation is particularly troubling as you document calls to method invocations without the context of the surrounding code which should plainly indicate why the method is being invoked. You suggest that the invocation should document the function of the invoked method which is presumptuous and most troubling to me. What if I change the way customers are notified, unless I go edit your comment it&#x27;s out if date even without other changes in that part of the system. You&#x27;ve undercut your entire argument with, &quot;Yes, a function should only do one thing, and perhaps that&#x27;s why my example isn&#x27;t the best.&quot;<p>If a function is written to do one thing then the context should be clear and there shouldn&#x27;t need to be comments.<p>Back to the differences between AP CSP (lots of comments) and Level 7 (no comments). The AP CSP course is written for novice programmers writing bad code that will never be used again. They need comments to understand what the code does. In the software craftsmanship course experienced coders are learning to write code for the future using good practices. And they are taught that if they need to add a comment then they need to rethink how the code was written and refactor.<p>There is one last thing that I want to bring up as I went through this process of coming to terms with comments. We began in the AP class discussing the need to comment changes in the code (bug fixes) to address writing prompts that focus on iteration. I realized that we have resolved the maintaining comments problem in the real world by moving comments into the commit messages in our VCS system. I&#x27;m able to see the justification for why a specific line of code has been changed, what it looked like originally and what test cases are relevant. In any decent IDE obtaining the commit message history for a given line of code is a few clicks and when not needed those comments aren&#x27;t in the way.<p>At the end of all of this introspection, I realized that I will probably be marking down candidates in technical interviews if they add comments. It&#x27;s a clear indication that the candidate values the clarity of simple code and understands the concept of encapsulation.