3 ms·
For many, many years, I've adopted the OP's choice of style, using what I call "FIRST/NEXT" comments to divide the function into paragraphs: // FIRST, Crea
by wduquette 3y ago
For many, many years, I've adopted the OP's choice of style, using what I call "FIRST/NEXT" comments to divide the function into paragraphs:
// FIRST, Create the pizza object
...
// NEXT, Add the toppings
...
// NEXT, Heat the oven
...
By all means, move a "paragraph" into its own function if it's called more than once; but otherwise this provides a number of useful features:
* The FIRST/NEXT comments serve as useful headers, making it possible to navigate the function without reading the code in detail.
* I know that no one's going to call one of the blocks from outside.
* I can see at a glance what chunks of code go together.
I've often gone back and read code I wrote five, ten, twenty, thirty years ago using this method, and found it perfectly readable.