Sometimes I want to write a "major" comment to describe a large block of code and then write "minor" comments to describe a few of the lines within that block of code:
// Major comment
// Minor comment
...
// Minor comment 2
...
The major comment looks strange without code directly beneath it, and you can't visually tell how much code it is describing below.
How do you style these comments?
(I remember reading about this in Code Complete a while ago but I don't own the book.)
I use multi-line comments for 'major' comments:
/*
* yada yada yada
*/
And use the single line comments for the minor ones.
I know some people don't like using /* */ style comments because it makes it harder to automatically comment and uncomment blocks ... but I like how they look, and I'm a strong believer that code should be aesthetically pleasing to read.
That also means that you should be able to parse the structure of the code largely without reading the details, which means I tend to use quite a lot of whitespace and also seperator comment lines to help break things up. So for a block I want to comment I might write:
/**
* detailed description ...
*/
code
// -- minor comment
code
code
// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
// Major comment // ------------- ... // Minor comment ... ... // Minor comment (end of line)
I use something like this, to make it look more like a "heading" or separator for the following block of code:
// ***** Major comment *****
// Minor comment
...
// Minor comment 2
...
Of course that assumes that the "major comment" is only a few words
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With