Keep Comments Close to the Corresponding Code [DS19]
Tip DS19
Comments are typically best placed close to the code they apply to. Comments that are too far away from the corresponding code are more difficult to read when working with code. That increases the chance that they’ll be overlooked and a programmer will miss out on important information…or miss out updating comments that need to be updated as code changes.
By co-locating comments near the corresponding code, they’ll be easier for programmers to read and update. Since comments aren’t typically checked by compilers like actual code, this will help comments stay up-to-date under maintenance.
The following demonstrates how comments far away from the code can be moved closer to the code: