All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Rethinking Programming Advice: The Case for Comments That Explain 'What'

By

zahrevsky

4mo ago· 3 min readenOpinion

Summary

The article challenges the common programming advice that "comments should explain why, not what." The author argues that comments explaining 'what' can be valuable, especially when code isn't immediately clear or when dealing with complex logic. They provide examples showing how explanatory comments can improve understanding, particularly for beginners or when revisiting code later. The piece acknowledges that clear code should be the goal but contends that 'what' comments serve as useful documentation and learning aids.

Key quotes

· 4 pulled
People say 'Comments should explain why, not what.' I feel like starting a flame war today so I'm going to argue that comments should explain 'what' too.
First of all, why shouldn't comments explain 'what'? If you need comments to explain what's going on, it suggests your code is unclear.
That's not as clear as saying weight = 10, radius = 9, price = 3
But it's obvious that w is weight! Sure, if you're seeing those lines back-to-back.
Snippet from the RSS feed
People say “Comments should explain why, not what.” I feel like starting a flame war today so I’m going to argue that comments should explain ‘what’ too. Please don’t use this as justification to write bad code, okay? Okay. First of all, why shouldn’t com

You might also wanna read