Alex Rivera | Logout

Why is '//' style multiline comment bad (in Java)?

Asked 2009-07-06T04:01:06.680
22

http://java.sun.com/docs/codeconv/html/CodeConventions.doc4.html#286

I was reading the above section of Java coding convention and started to wonder why it says "// comment.....shouldn't be used on consecutive multiple lines for text comments"

Copy pasted the relevant section here for convenience:

The // comment delimiter can comment out a complete line or only a partial line. It shouldn't be used on consecutive multiple lines for text comments; however, it can be used in consecutive multiple lines for commenting out sections of code.

Is there any rational reason for this?

Edit
Report

1 Answer

0

I've always thought that /* */ style comments were required for multi-line comments because // was allowed "in consecutive multiple lines for commenting out sections of code." Code formatting tools need to be able to easily distinguish multi-line comments from commented out code.

If you tell a code formatting tool (or your IDE) to cleanup your file, you would likely want it to re-wrap multi-line comments to the margin, wrapping at the spaces. You would not what the tool to wrap commented out code this way.

That all said, many style rules are at least slightly arbitrary, so there may not have been a strong reason why Code Conventions for the Java Programming Language specified /* / style comments were required for multi-line comments. They could have instead decided to use / */ style comments only for commenting out code, and use // style comments for single and multi-line comments.

answered 2009-07-06T04:56:33.417

Your Answer