Ind*_*thi 21 java comments coding-style
http://java.sun.com/docs/codeconv/html/CodeConventions.doc4.html#286
我正在阅读Java编码约定的上述部分,并开始想知道它为什么说"//注释.....不应该连续多行用于文本注释"
为方便起见,复制粘贴到相关部分:
//注释分隔符可以注释掉一个完整的行或只注释一个部分行.它不应该在连续的多行上用于文本注释 ; 但是,它可以在连续的多行中用于注释掉代码段.
这有什么合理的理由吗?
Swa*_*nny 39
实际上,我//多年来一直在使用多行,并且从未遇到任何严重的问题.我/*...*/不再喜欢了,因为你得到:
/* I'm commenting out all this code for a moment
...
/* And here is a multi line comment
that was hidden in the middle */
...
*/
Run Code Online (Sandbox Code Playgroud)
感谢编译器它感到不安并告诉我这个问题.
在哪里:
...
// And here is a multi line comment
// that was hidden in the middle
...
Run Code Online (Sandbox Code Playgroud)
变成一个宏:
// ...
// // And here is a multi line comment
// // that was hidden in the middle
// ...
Run Code Online (Sandbox Code Playgroud)
并且很高兴与另一个将其返回原始形式的宏相反
至于:
// but now you have
// trouble edditing
// your comments so
// that every line
// is of equal size
Run Code Online (Sandbox Code Playgroud)
我说:
// 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
Run Code Online (Sandbox Code Playgroud)
你不喜欢厌恶:
/******************************************************************
* 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!!!!!!!!!!!!! *
******************************************************************/
Run Code Online (Sandbox Code Playgroud)
似乎总是出现在坚持/* */结束的地方//
而且我想对Stack Overflow的人说,这是非常酷的编辑器.做代码示例非常简单.
lev*_*vik 12
这个想法是多行文本注释是一个实体 - 您希望在逻辑上保持在一起.这样的评论中的换行符只不过是用于包装文本的地方,因此将其分解为许多"单独"的注释是没有意义的.因此,围绕整个事物构建一个注释块 - 使用/**/.
为了注释掉代码,每一行都是它自己的逻辑单元,所以使用连续的"//"是有的 - 有时候.如果出于某种原因可以将"单个行"注释回"in",尤其是所有行,则尤其如此.虽然如果你想要注释掉一个完整的块代码,在那里部分注释它是不可能有意义的,你可能仍然喜欢再次使用/**/ - 将所有内容逻辑地和可视地组合在一起.
这使得修改和格式化长评论变得极其痛苦。
大多数编辑器提供某种换行工具来自动将文本换行为可读长度的行。如果每行都以“//”开头,那么这些行将被移动,然后必须被删除,并重新插入新的。使用 '/* */ 风格的注释可以避免所有这些繁琐的工作。
| 归档时间: |
|
| 查看次数: |
11332 次 |
| 最近记录: |