Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> If I don't do this, when I come back to the code an hour later

Good coding means two things, in general:

* There is no more understandable comment than no comment needed.

The code should explain _what_ it is doing as close as possible in words such that any programmer, including you, can read the code and understand what it is doing.

Bad: sum = a.length + b.length

Good: totalNumberOfGoodProducts = exceptionalProducts.length + acceptableProducts.length

* Comments should be the exception for _why_ something odd is happening.

Bad: if(r == 42) return; // Nothing happened.

Good: if(ioReturnCode == 42) return; // Ignoring code 42, an undocumented value and seems to be a "no operation happened." We'll retry again later in the code.



Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: