评论风格? [英] Commenting style?

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

问题描述

有人可以推荐一个很好的C / C ++编码风格来源。

具体来说,我有兴趣评论风格和

特别是如何缩进评论和评论代码,而不是使用评论时的
。提前致谢!

-

[见 http://www.gotw.ca/resources/clcm.htm 有关的信息]

[comp.lang.c ++。moderated。第一次海报:做到这一点! ]

Can someone recommend a good source of C/C++ coding style.
Specifically, I am interested in commenting style and in
particular how to indent comments and the commented code, rather
than when to use comments. Thanks in advance!
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

推荐答案

基本上附加的是类布局和源代码布局......你可以看到
评论部分。此外,如果你想评论一个大的

代码,但同时你不想删除代码

使用#ifdef赞


#ifdef JUST_FOR_COMMENTING_OUT

这里你不想执行的代码

#endif


希望这有帮助!


Satish


############## CLASS LAYOUT ###### ####################

/ **

*该类的一行描述。 />
*

* #include" XX.h" < BR>

* -llib

*

*更长的描述。

*

* @see something

* /


#ifndef XX_h

#define XX_h


//系统包括

//


//项目包括

//


//当地包括

//


//前瞻参考

//


class XX

{

public:

// LIFECYCLE


/ **

*默认构造函数。

* /

XX(无效);


/ **

*复制构造函数。

*

* @param from要复制到此对象的值。 />
* /

XX(const XX& from);


/ **

*析构函数。

* /

~XX(无效);


//运营商


/ **

*作业运算符。

*

* @param从该值分配给该对象。

*

* @return对这个对象的引用。

* /

XX& operator =(XX& from);


//操作

//访问

//查询


受保护:

私人:

};


//外部参考

//


#endif // _XX_h_


附录B - 源文件代码布局

#包括XX.h和XX.h。 //课堂实施


/////////////////////////////// PUBLIC

///////////////////////////////////////
< br $>
// =============================生命周期

=== =================================

XX :: XX( )

{

} // XX

XX :: XX(const XX&)

{

} // XX


XX :: ~XX()

{

} // ~XX


// =============================运算符

====================================

XX&

XX :: operator =(XX&);

{

return * this;


} // =


// ======================== =====运营

===================================

// ============================= ACESS

=== ================================

// ======== =====================查询

==================== ===============

/////////////////////////// /// / PROTECTED

///////////////////////////////////
< br $>
/////////////////////////////// PRIVATE

/// ////////////////////////////////


Angel Tsankov写道:
Basically attached is the class layout and source code layout... You
can see the comments section. Also if you want to comment a large
piece of code but at the same time you don''t want to delete the code
use #ifdef like

#ifdef JUST_FOR_COMMENTING_OUT
code here which you dont want to execute
#endif

Hope this helps!

Satish

##############CLASS LAYOUT##########################
/**
* A one line description of the class.
*
* #include "XX.h" <BR>
* -llib
*
* A longer description.
*
* @see something
*/

#ifndef XX_h
#define XX_h

// SYSTEM INCLUDES
//

// PROJECT INCLUDES
//

// LOCAL INCLUDES
//

// FORWARD REFERENCES
//

class XX
{
public:
// LIFECYCLE

/**
* Default constructor.
*/
XX(void);

/**
* Copy constructor.
*
* @param from The value to copy to this object.
*/
XX(const XX& from);

/**
* Destructor.
*/
~XX(void);

// OPERATORS

/**
* Assignment operator.
*
* @param from THe value to assign to this object.
*
* @return A reference to this object.
*/
XX& operator=(XX& from);

// OPERATIONS
// ACCESS
// INQUIRY

protected:
private:
};

// EXTERNAL REFERENCES
//

#endif // _XX_h_

APPENDIX B - Source File Code Layout
#include "XX.h" // class implemented

/////////////////////////////// PUBLIC
///////////////////////////////////////

//============================= LIFECYCLE
====================================

XX::XX()
{
}// XX

XX::XX(const XX&)
{
}// XX

XX::~XX()
{
}// ~XX

//============================= OPERATORS
====================================

XX&
XX::operator=(XX&);
{
return *this;

}// =

//============================= OPERATIONS
===================================
//============================= ACESS
===================================
//============================= INQUIRY
===================================
/////////////////////////////// PROTECTED
///////////////////////////////////

/////////////////////////////// PRIVATE
///////////////////////////////////


Angel Tsankov wrote:

有人可以推荐一个很好的C / C ++编码风格来源。

具体来说,我有兴趣评论风格和在

特别是如何缩进评论和注释代码,而不是使用评论时的
。提前致谢!
Can someone recommend a good source of C/C++ coding style.
Specifically, I am interested in commenting style and in
particular how to indent comments and the commented code, rather
than when to use comments. Thanks in advance!



-

[见 http://www.gotw.ca/resources/clcm.htm 有关的信息]

[comp.lang。 C ++。主持。第一次海报:做到这一点! ]


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


[交叉发布删除]


Satish写道:
[cross-posting deleted]

Satish wrote:

基本上附加的是类布局和源代码布局......你可以看到
的评论部分。此外,如果你想评论一个大的

代码,但同时你不想删除代码

使用#ifdef赞


#ifdef JUST_FOR_COMMENTING_OUT

这里你不想执行的代码

#endif


希望这有帮助!


Satish


############## CLASS LAYOUT ###### ####################

/ **

*该类的一行描述。 />
*

* #include" XX.h" < BR>

* -llib

*

*更长的描述。

*

* @see something

* /


#ifndef XX_h

#define XX_h


//系统包括

//


//项目包括

//


//当地包括

//


//前瞻参考

//


class XX

{

public:

// LIFECYCLE


/ **

*默认构造函数。

* /

XX(无效);


/ **

*复制构造函数。

*

* @param from要复制到此对象的值。 />
* /

XX(const XX& from);


/ **

*析构函数。

* /

~XX(无效);


//运营商


/ **

*作业运算符。

*

* @param从该值分配给该对象。

*

* @return对此对象的引用。

* /

XX& operator =(XX& from);


//操作

//访问

//查询


受保护:

私人:

};


//外部参考

//


#endif // _XX_h_


附录B - 源文件代码布局


#include" XX.h" //课堂实施


/////////////////////////////// PUBLIC

///////////////////////////////////////
< br $>
// =============================生命周期

=== =================================

XX :: XX( )

{

} // XX

XX :: XX(const XX&)

{

} // XX


XX :: ~XX()

{

} // ~XX


// =============================运算符

====================================

XX&

XX :: operator =(XX&);

{

return * this;


} // =


// ======================== =====运营

===================================

// ============================= ACESS

=== ================================

// ======== =====================查询

==================== ===============

/////////////////////////// ////保护ED

///////////////////////////////////
/>
/////////////////////////////// PRIVATE

//// ///////////////////////////////


Angel Tsankov写道:
Basically attached is the class layout and source code layout... You
can see the comments section. Also if you want to comment a large
piece of code but at the same time you don''t want to delete the code
use #ifdef like

#ifdef JUST_FOR_COMMENTING_OUT
code here which you dont want to execute
#endif

Hope this helps!

Satish

##############CLASS LAYOUT##########################
/**
* A one line description of the class.
*
* #include "XX.h" <BR>
* -llib
*
* A longer description.
*
* @see something
*/

#ifndef XX_h
#define XX_h

// SYSTEM INCLUDES
//

// PROJECT INCLUDES
//

// LOCAL INCLUDES
//

// FORWARD REFERENCES
//

class XX
{
public:
// LIFECYCLE

/**
* Default constructor.
*/
XX(void);

/**
* Copy constructor.
*
* @param from The value to copy to this object.
*/
XX(const XX& from);

/**
* Destructor.
*/
~XX(void);

// OPERATORS

/**
* Assignment operator.
*
* @param from THe value to assign to this object.
*
* @return A reference to this object.
*/
XX& operator=(XX& from);

// OPERATIONS
// ACCESS
// INQUIRY

protected:
private:
};

// EXTERNAL REFERENCES
//

#endif // _XX_h_

APPENDIX B - Source File Code Layout
#include "XX.h" // class implemented

/////////////////////////////// PUBLIC
///////////////////////////////////////

//============================= LIFECYCLE
====================================

XX::XX()
{
}// XX

XX::XX(const XX&)
{
}// XX

XX::~XX()
{
}// ~XX

//============================= OPERATORS
====================================

XX&
XX::operator=(XX&);
{
return *this;

}// =

//============================= OPERATIONS
===================================
//============================= ACESS
===================================
//============================= INQUIRY
===================================
/////////////////////////////// PROTECTED
///////////////////////////////////

/////////////////////////////// PRIVATE
///////////////////////////////////


Angel Tsankov wrote:

有人可以推荐一个很好的C / C ++编码风格来源。

具体来说,我有兴趣评论风格和

特别是如何缩进评论和评论代码,而不是使用评论时的
。提前致谢!
Can someone recommend a good source of C/C++ coding style.
Specifically, I am interested in commenting style and in
particular how to indent comments and the commented code, rather
than when to use comments. Thanks in advance!



Satish,请不要在这里发帖(请参阅
http://www.parashift.com/c ++ - faq-lit ... .html#faq-5.4)

其次,格式化风格在很大程度上取决于偏好。 OP可以在常见问题解答中找到一些指南和链接

http://www.parashift.com/c++-faq-lit...standards.html )并且可以

谷歌更多,但格式化最重要的是

一致性。


就个人而言,我宁愿不使用预处理器来;评论

out"像萨蒂什这样的代码在上面。相反,我使用//评论整个

并使用/ ** / comments来摆脱块和/或正则表达式

搜索和替换添加//到我希望每行开头

评论出来。


干杯! --M

Satish, please don''t top-post here (see
http://www.parashift.com/c++-faq-lit....html#faq-5.4).
Second, formatting style is largely a matter of preference. The OP can
find some guidelines and links in the FAQ
(http://www.parashift.com/c++-faq-lit...standards.html) and can
google for more, but the most important thing with formatting is
consistency.

On a personal note, I prefer not to use the preprocessor to "comment
out" code like Satish does above. Instead I use // comments throughout
and use /**/ comments to get rid of blocks and/or regular expression
search-and-replace to add // to the beginning of each line I want to
comment out.

Cheers! --M


* mlimber:
* mlimber:

>

就个人而言,我宁愿不使用预处理器来评论

out。像萨蒂什这样的代码在上面。相反,我使用//评论整个

并使用/ ** / comments来摆脱块和/或正则表达式

搜索和替换添加//到我希望每行开头

评论出来。
>
On a personal note, I prefer not to use the preprocessor to "comment
out" code like Satish does above. Instead I use // comments throughout
and use /**/ comments to get rid of blocks and/or regular expression
search-and-replace to add // to the beginning of each line I want to
comment out.



同意//评论在视觉上不那么强烈。而且很遗憾

/ *。* /不要嵌套,需要使用条件编译

作为评论输出设备。然而,在Satish的帖子中显示的示例

的主要问题 - 顺便说一句似乎是针对某些文档生成器的b
bb分类

班级成员;在实践中这种固定的分类很少,如果

,则对应于任何自然分区或

代码的自然布局。就在现在:我看到Satish多次发布相同的例子

到comp.lang.c ++。版主。也许对这个例子的讨论是

更好地移动到那里......

C#,以便创建逻辑组(在智能编辑器中可折叠)。


但它不是。


-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门发布。

问:usenet和电子邮件中最烦人的事情是什么?

Agreed that // comments are less visually imposing. And it''s a shame
that /*...*/ don''t nest, necessitating using condititional compilation
as a commenting-out device. However, the main problem with the example
shown in Satish''s posting -- which by the way seems to be geared
towards some documentation generator -- is the attempt at classifying
class members; in practice such fixed classifications very seldom, if
ever, correspond to any natural division nor a natural layout of the
code. Just in now: I see that Satish is multi-posting the same example
to comp.lang.c++.moderated. Perhaps discussion of that example is
better moved there...

It would be nice if the C++ preprocessor had a #region directive like
C#, in order to create logical groups (collapsible in smart editors).

But it doesn''t.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


这篇关于评论风格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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