Doxygen C++惯例

发布于 2024-09-15 08:49:34 字数 638 浏览 4 评论 0原文

我正处于 C++ 项目的开始阶段,并且从一开始就一直在使用 Doxygen。

我想知道您在项目中如何使用Doxygen,即我有几个问题:

1。您将 Doxygen 评论放在哪里?标头或来源?

我认为它们应该转到标头,因为这是我查找如何使用方法的地方。但是,我喜欢在原型中省略实际参数名称,因此我不能使用 @param - 或者可以吗?你如何解决这个问题?

2.您是否记录了所有方法?

到目前为止我只记录了公共方法,您是如何做到的?您是否记录了访问器方法和公共变量?

3.你总是填写@param和@return吗?

在我工作的地方(它是Javadoc,但它是同一个问题),我们有一个约定,只填写实际需要的属性,即如果简短的描述说“返回xys if ...”,我们省略@return。如果参数名称很明显,我们将省略它们。我仍然不确定我是否喜欢这种方法,你是怎么做的?到目前为止,我只填写了概要,没有其他任何内容,但并非所有方法原型都足够简单。

4.您使用哪种样式?

Doxygen 中有多种样式:Javadoc (/** ... /)、QT (/! ... */) 等等。纯粹出于兴趣:您使用哪一个?我将使用 Javadoc 风格的 ATM,因为我已经习惯了。

I'm at the beginning of a C++ project and I've been using Doxygen from the start.

I'd like to know how you use Doxygen in your project, i.e. I have several questions:

1. Where do you put your Doxygen comments? Header or sources?

I think that they should go to the header, because that's where I look to find out how to use methods. However, I like to omit actual parameter names in prototypes, so I can not use @param - or can I? How do you tackle this?

2. Do you document all methods?

I'm only documenting public methods so far, how do you do it? Do you document accessor methods and public variables?

3. Do you always fill out @param and @return?

Where I work (it's Javadoc, but it's the same issue), we have a convention to fill only actually needed properties, i.e. if the brief descriptions says "Returns xys if ...", we omit @return. If the parameter names are obvious, we omit them. I'm still not sure if I like that approach, how do you do it? So far, I've only filled out the brief and nothing else, but not all method prototypes are straightforward enough for that.

4. Which style do you use?

There are several styles in Doxygen: Javadoc (/** ... /), QT (/! ... */) and more. Purely out of interest: Which one do you use? I'm going with Javadoc style ATM because I'm used to it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮光之海 2024-09-22 08:49:34

<强>1。您将 Doxygen 评论放在哪里?标题或来源?

我无法回答这个问题,因为我实际上不记得我倾向于在哪里用标头和源来记录。

<强>2。您记录了所有方法吗?

几乎完全是。每个方法都有某种形式的文档,除非从变量/方法名称(以及方法的参数名称)中可以立即明显看出它的具体作用。我倾向于遵循这样的规则:“如果你无法通过名称和参数名称弄清楚方法的用途,则需要注释。如果注释后你仍然无法弄清楚方法的用途,请重写如果您仍然无法很快看出该方法的用途,或者注释“太长”(其中“太长”是任意测量>_>),那么您需要重新编写该方法。或者把它分开。”

<强>3。你总是填写@param和@return吗?

是的。即使从阅读 @brief 中显而易见,或者如果 @return@brief 中句子的精确副本,我仍然填写它们。为方法的文档提供这种扫描属性可能非常有用。 “哦,方法X,我知道它的作用和原因,但是在X情况下它的返回值到底是什么?” *检查@return*。

<强>4。您使用哪种风格?

Javadoc 我自己,尽管这完全是主观的。我使用 Javadoc 语法是因为我花了一段时间用 Java 编写并且非常习惯该语法。我个人也认为它比其他的更有意义——我只是根本不喜欢 QT 语法。

1. Where do you put your Doxygen comments? Header or sources?

I can't answer this because I actually don't currently remember where I tend to document in terms of header versus source.

2. Do you document all methods?

Almost completely yes. Every single method gets some form of documentation, unless it is instantly obvious from the variable/method name (and parameter names for methods) what it does in specifics. I tend to go by the rule of "If you can't work out the purpose of a method by it's name and parameter names, it needs a comment. If after commenting you still cannot work out the purpose of the method, re-write the comment. If you still cannot see very quickly the purpose of the method, or if the comment is 'too long' (where 'too long' is an arbitrary measurement >_>), then you need to re-write the method or split it up."

3. Do you always fill out @param and @return?

Yes. Even if it's blindingly obvious from reading the @brief, or if the @return is an exact copy of sentence in the @brief, I still fill them in. It can be very useful to have that sort of scan property for a method's documentation. "Oh, method X, I know what it does and why, but what exactly is its return value in X situation again?" *checks the @return*.

4. Which style do you use?

Javadoc myself, although this is completely subjective. I use the Javadoc syntax because I spent a while writing in Java and got very used to that syntax. I also personally think it makes more sense than the others – I just don't like the QT syntax at all.

提笔书几行 2024-09-22 08:49:34

<强>1。您将 Doxygen 评论放在哪里?标题或来源?

文档位于标头中,因为这是定义接口的地方。

<强>2。您记录了所有方法吗?

对于类,我记录了所有公共和受保护的方法,通常只保留私有方法。

<强>3。你总是填写@param和@return吗?

我更喜欢使用内联参数文档

/*!
 * \brief My great class.
 */
class Foo
{
public:
    /*!
     * \brief My great method.
     */
    void method(
        int parameter    //!< [in] parameter does something great
    );
};

而不是使用\param,因为它会导致参数名称重复,并且很容易与当懒惰的开发人员忘记更改 doxygen 时的代码。

当存在 void 返回类型时,\return 被省略。当方法可以抛出时,我总是使用 \throw

4.您使用哪种风格?

只要在整个项目中保持一致就可以了。

1. Where do you put your Doxygen comments? Header or sources?

Documentation goes in headers since this is where the interface is defined.

2. Do you document all methods?

For classes, I document all of the public and protected methods, I generally leave private methods alone.

3. Do you always fill out @param and @return?

I prefer the inline parameter documentation

/*!
 * \brief My great class.
 */
class Foo
{
public:
    /*!
     * \brief My great method.
     */
    void method(
        int parameter    //!< [in] parameter does something great
    );
};

to using \param since it results in duplication of the parameter name, and can easily get out of sync with the code when lazy developers forget to change the doxygen.

\return is omitted when there's a void return type. I always use \throw when the method can throw.

4. Which style do you use?

Does not matter as long as its consistent in the entire project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文