为什么'//'样式多行注释不好(在Java中)? [英] Why is '//' style multiline comment bad (in Java)?

查看:118
本文介绍了为什么'//'样式多行注释不好(在Java中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我正在阅读上述Java编码约定部分,开始怀疑为什么它说 // comment .....不应在连续的多行上使用文本注释

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.

推荐答案

实际上,我一直在使用 // 多年以来从未遇到任何严重问题。我不再是 /*...*/ 的忠实拥护者,因为您会得到:

Actually, I've been using // for multiple lines for years and never suffered any serious problem with it. I'm not a big fan of /*...*/ anymore because you get:

/* I'm commenting out all this code for a moment
  ...
  /* And here is a multi line comment
     that was hidden in the middle */
  ...
*/ 

感谢编译器不高兴并告诉我问题所在。

Thank the compiler it gets upset and tells me of the problem.

其中:

...
// And here is a multi line comment
// that was hidden in the middle
...

变成一个宏:

// ...
// // And here is a multi line comment
// // that was hidden in the middle
// ...

,并很高兴地用另一个宏将其恢复为原始格式

and is happily reversed with another single macro that returns it back to the original form

,如下所示:

  // but now you have 
  // trouble edditing
  // your comments so
  // that every  line
  // is of equal size

我说:

  // Tough, this is a piece of code not a 
  // published novel
  // and if varying lengths
  // make
  // it hard for you to read then heaven
  // forbid how you handle the code

而且,您不只是讨厌教育吗?

And don't you just hate edditing:

/******************************************************************
 * Program: Foo.java                                              *
 ******************************************************************
 * Author:  Codey Art Work                                        *
 * Purpose: To do something with something and get something not  *
 *          forgetting something else.                            *
 ******************************************************************
 * Revision History:                                              *
 ******************************************************************
 *  Date  | Author |                                              *
 *--------|--------|----------------------------------------------*
 * 1/2/09 | Jack   | Now I have to keep all my comments in this   * 
 *        |        | tiny little space and if I edit it I just go *
 *        |        | aaarrrrrrggggggggggghhhhhhhhhhh!!!!!!!!!!!!! *
 ******************************************************************/

似乎总是出现在要求 / * * / 超过 //

which always seem to appear in places insisting on /* */ over //


我想对Stack Overflow的家伙说,这真的很酷。进行代码示例非常容易。

这篇关于为什么'//'样式多行注释不好(在Java中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆