Two's Complement cover image

Two's Complement

Questionable Comments

Sep 18, 2023
Ben and Matt explore the purpose and characteristics of good comments in code, discuss the management of to-do comments in codebases, and emphasize the role of comments in thread safety and code understanding. They also outline the risks of leaving commented out code and suggest alternatives like source control and refactoring.
42:17

Podcast summary created with Snipd AI

Quick takeaways

  • Good comments focus on the 'why' rather than the 'how', providing insights that are not evident by simply reading the code.
  • Comments can be useful for documenting code, but care should be taken to avoid duplicating code or stating the obvious.

Deep dives

The Importance of Writing Good Comments in Code

Writing good comments in code is essential as they provide clarity and context to readers. Engineers often ask applicants to write code and explain their choices to understand their thought process. Comments serve as a communication tool between developers and express the intentions behind certain decisions. However, not all comments are valuable. Comments that state the obvious or duplicate code are considered bad comments. Extracting code into functions with meaningful names can often make comments unnecessary. Good comments focus on the 'why' rather than the 'how', providing insights that are not evident by simply reading the code. Additionally, comments that document potential issues, thread safety requirements, or cross-references to external documentation can be helpful. On the other hand, comments should never substitute for proper documentation or rely on commented-out code. Leveraging version control and pre-commit hooks can prevent accidental commits of commented-out code or code meant only for testing purposes.

Remember Everything You Learn from Podcasts

Save insights instantly, chat with episodes, and build lasting knowledge - all powered by AI.
App store bannerPlay store banner