Comment style: Imperative or third person

coding-stylecomments

I have a question relating programming and english language both: Whether to use third person or imperative when commenting single lines of code.
Assume following line of code in a imperative language which should be commented:

object.doSomething();

My approach to comment this line would be to put the comment behind it using third person like this would be a ordinary english sentence containing the line as subject:

object.doSomething(); // does (referencing to the line of code) some action

But since we are in a imperative language and thus actually "commanding" the computer, one could even think of putting the comment before the code and using imperative:

//Do some action:
object.doSomething();

This is even useful when one need to comment multiple lines related to each other.

I personally prefer the first style but i often feel unsure about what style to use. It would be great if some could write their personal experience down here.

Best Answer

Oracle's official style guide states:

Use 3rd person (descriptive) not 2nd person (prescriptive). The description is in 3rd person declarative rather than 2nd person imperative.

Gets the label. (preferred)

Get the label. (avoid)

Oracle's style guide can be found here.