注释约定 [英] Commenting Conventions

查看:78
本文介绍了注释约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道有哪些评论指南?我在Java中为类编码。我想要有可读的代码。在另一个问题,我被告知如何评论应该保留为困难的代码段。我被告知,我的代码注释添加了没有知道的信息。评论不仅仅是给读者。他们还提醒作者他们最初的意图,并帮助匹配分组符号。

I want to know what are some guidelines for commenting? I am coding in Java for class. I want to have readable code. In another question I was told "how" comments should be reserved for difficult sections of code. I was told that my code comments added no knew information. Comments are not only for readers. They are also reminders to the writer of their original intent and to help match grouping symbols.

我是Java和Stackoverflow的新手。为什么我变得灰白?我认为这个网站是为了让程序员互相帮助。我觉得像一个目标,因为我有一个-3投票的问题。

I am new to Java and Stackoverflow. Why am I getting greifed? I thought this website was designed to allow programmers to help each other. I feel like a target because I have a question with a -3 vote. Are we here to help new programmers or here to puff up our chests with pride at others expense?

推荐答案

不同的人有不同的风格,所以在某种程度上,你在这里读到的只是一个人的建议。

Different people have different styles, so to some extent whatever you read here will be just someone's suggestions. There are no cold, hard rules for commenting.

在Java中评论的最重要的事情是Javadocing。它是一种特殊类型的注释,可以解析出来并在IDE(如Eclipse和Netbeans)中使用,以帮助使编码过程更容易。 Javadoc注释以/ **开始,以* /结束,就像一个常规的多行注释,但在第一个注释中有两个星号。

The most important thing you should know about commenting in Java is Javadocing. It's a special type of comment that can be parsed out and used in IDEs (like Eclipse and Netbeans), to help make the coding process easier. Javadoc comments start with a /** and end with a */ It's just like a regular multi-line comment but with two asterisks in the first one.

注释在类,方法或实例变量的开头描述它们的作用。有一些标准的方法来格式化注释中的数据,这些都是标签。一些常见的标签是@author和@version。你可以在这里看到Sun写的Javadoc注释的一些建议: http://java.sun。 com / j2se / javadoc / writingdoccomments /

You put Javadoc comments at the beginning of classes, methods, or instance variables to describe what they do. There are standard ways to format data in the comment, which are tags. Some common tags are @author and @version. You can see some of Sun's suggestions for writing Javadoc comments here: http://java.sun.com/j2se/javadoc/writingdoccomments/

我喜欢做的是使用单行注释(双斜线//)来描述我的逻辑。如果我需要多行,我将使用多个单行注释。这种技术的优点是,如果您需要稍后注释掉大量文本,您可以使用常规多行注释/ * * /而不必担心嵌套注释问题。

What I like to do after that is use single-line comments ( the double slash // ) to describe my logic. If I need more than one line, I'll just use multiple single-line comments. The advantage of this technique is that if you need to later comment out large swaths of text, you can use the regular multi-line comment /* */ without worrying about the nested comment problem.

我希望这能帮助你大致了解如何在java中使用注释。我的建议部分是一个教学助理工作的产品,我有一个大学的简介Java类和部分从工作在工业。其他具有不同背景的用户可能会有更多建议。

I hope that helps you get a rough idea of how to use comments in java. My advice is partly a product of the teaching assistant job I have for a university's Intro Java class and partly from working in industry. Others with different background may have more suggestions.

这篇关于注释约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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