Today I Learned - Rocky Kev

TIL the value of a good comment

POSTED ON:

TAGS:

Comments are not evil. They are as necessary to programming as basic branching or looping constructs. Most modern languages have a tool akin to javadoc that will parse properly formatted comments to automatically build an API document. This is a very good start, but not nearly enough. Inside your code should be explanations about what the code is supposed to be doing. Coding by the old adage, "If it was hard to write, it should be hard to read," does a disservice to your client, your employer, your colleagues, and your future self.

On the other hand, you can go too far in your commenting. Make sure that your comments clarify your code but do not obscure it. Sprinkle your code with relevant comments explaining what the code is supposed to accomplish. Your header comments should give any programmer enough information to use your code without having to read it, while your in-line comments should assist the next developer in fixing or extending it.

I follow this adage: Make the next developer's life easier. Sometimes it's comments, sometimes it's just really clear code. Who that developer is also important. If it's a junior, maybe add a bit more detail. If it's to a lead, maybe it's less.

Thing 16 of 97 things Ebook


Related TILs

Tagged:

TIL the Singleton Pattern is hotly debated

Singleton Pattern is useful when exactly one object is needed to be used as a global instance to coordinate across the system. But it got problems.

TIL The Single Responsibility Principle

Gather together those things that change for the same reason, and separate those things that change for different reasons... if it makes sense.

TIL KISS (Keep it simple stupid)

I'm a fan of Keep it Stupidly Simple (KISS) (There's other ways to interpret the the last part).