What is the best way to put comments in your code? I see at least three different ways:
1:
int i = 10; //Set i to 10
2:
//Set i to 10
int i = 10;
3:
int i = 10;
//Set i to 10
The disadvantage of using the first method is that many people use tabs instead of spaces, and doing so will cause comments to become severely misaligned when the tab size changes.
The second and third snippets avoid this problem, but when having a lot of code it is sometimes unclear which line a comment is referring to.
Option 3 Is just wrong. All tools I know expect method docs before the method like in 2. So doing the opposite inside a method is confusing.
Otherwise, 1 & 2 are both ok but I’d only use 1 on short lines of code. Generally, 2 would be my preferred option because not only is it consistent with comment conventions for methods/classes, you see the comment before the code.