Hacker News new | ask | show | jobs
by einhverfr 4484 days ago
You can take this a little further by separating your comments into two groups:

1. An english language description of what the function (or code block) does as a black box (forget the internals as they are subject to change). What you put in and what you get out, or section headings to structure how you read the code.

2. Comments in the code block to tell you why a given decision was made.

What this gives you is the framework you are describing but it further cements it into three layers:

1. Function and block documentation describe contract and what the code is expected to do from outside. If the code does not implement the contract the code is wrong.

2. When reading through the code as contract-implementation you can understand why certain decisions were made.

As bonus points, you get good API documentation.