Don’t Have Blank Lines Between Comments and the Code They Apply To [DS22]
Tip DS22
Blank lines can be used to “separate” unrelated things. By implication, that also means that things that aren’t separated by blank lines are grouped together and thus are likely related. If comments are too far separated from the corresponding code, that introduces uncertainty for a reader as to if the comments actually apply to that code or if something might be missing. Therefore, avoid having blank lines between comments and the corresponding code.
See the following example:
The comments in the original version of the code above are not that far away from the actual code (and don't really have any code in-between them), but the blank lines of space separate the comments from the related code, making it seem like they're not related. Having the comments directly before the code (without intervening whitespace) makes the connection between the comments and the code clearer.
Extra blank lines also reduces the amount of code that can be seen on-screen at once, so removing unnecessary blank lines can make it easier for a reader to comprehend the code.