A junior engineer writes comments that explain what the code does. A mid-level engineer writes comments that explain why the code does what it does. A senior engineer writes comments that explain why the code isn’t written in another way.
Comments also explain context to automated developers (e.g. LLM agents) interacting with the code.
Josh Beckman