logoalt Hacker News

bottlepalmtoday at 4:06 AM2 repliesview on HN

If you can't understand why the code is done in a certain way from reading it then the code is missing comments or needs to be refactored.

Even code you write yourself, given enough time, you will forget the why unless you wrote comments. In a way comments are as much for you as they are for others.

Even before AI, understanding code you didn't write is essential to working on a team of other developers. If you can't understand the code from reading it, then that's part of the feedback loop - too complex, needs comments, etc..

On large teams you'll spend as much time reading code as you do writing it. And long term when it comes to writing maintainable code - the ability for others to read and understand it, including the why of it, is paramount. Your code could literally be around for decades.


Replies

locknitpickertoday at 5:03 AM

> If you can't understand why the code is done in a certain way from reading it then the code is missing comments or needs to be refactored.

Code is never missing contexts. If what your code is doing is not obvious to the reader, it is bad code that needs to be fixed. Things like cryptic low-level expressions should be extracted to helper functions with descriptive names or even extracted into a class, and classes need to comply with the single responsibility principle.

show 1 reply
manmaltoday at 4:35 AM

Codex barely writes any comments, while Claude makes a slop article for every one line commit. I’d enjoy something in the middle.