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

前端 未结 8 1712
甜味超标
甜味超标 2021-02-05 07:15

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 \"// com

8条回答
  •  忘了有多久
    2021-02-05 07:26

    Even commenting large quantity of code with // can be quite horrible sometimes.

    I use Eclipes and although I really enjoy the drudgery it takes out of everyday programming there are some feature combination that can give weird results... for example..

    select large block of code that already contains some // multiline commented out code, press ctrl-/ and comment it all out, then do ctrl-shift-f to format your code, if for some reason your formatter deals with comments it will reformat your code. Then reselect the whole thing and uncomment it with ctrl-/ again...

    some format options will just screw around the commented out code and relay-it all out, when you uncomment it all hell breaks loos and you will have to parse it and reformat it manually.

    I admit this is anecdotal, I have since reconfigured eclipse to not do this anymore but I also refrain now from using // for such large code comment swath in favor of the /* */. However there are many other options that are better to use :

    /** for Javadoc comment */ this way the comments are accessible in code complete, documentation etc... comment once, use everywhere.

    If you know you are going to create multi line comment that is not java doc then starting it with /* the IDE will take care of the rest as far as formatting goes. So to explain weird algorithms of patching in the code I will use /* */ rather than //. I keep it for single liner when necessary.

    My 2 cent

提交回复
热议问题