Chapter 5. A PASSING COMMENT

How to Write Code Comments

Comments are free but facts are sacred.

Charles Prestwich Scott

Comments are a lot like opinions. You’re free to make them, but just because you do doesn’t mean they’re right. In this chapter, we’ll spend a little time thinking about the details of writing these things. There’s a lot more to writing comments than you’d think.

Probably one of the first things you learned when you were taught to program was how to write comments. You were told that comments aid the readability of code, and you were probably encouraged to write lots of them. But in this game, we need to be thinking more about quality than quantity. Comments are our lifelines, memory jogs, and guides through code. We should treat ...

Get Code Craft now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.