C++核心准则​NL.17:使用K&R风格派生的布局

网友投稿 618 2022-11-12

C++核心准则​NL.17:使用K&R风格派生的布局

C++核心准则​NL.17:使用K&R风格派生的布局

NL.17: Use K&R-derived layout

NL.17:使用K&R风格派生的布局

Reason(原因)

This is the original C and C++ layout. It preserves vertical space well. It distinguishes different language constructs (such as functions and classes) well.

这是原始的C和C ++布局。它很好地保留了垂直空间。它很好地区分了不同的语言构造(例如函数和类)。

Note(注意)

In the context of C++, this style is often called "Stroustrup".

在C ++的上下文中,此样式通常称为“斯特劳斯特卢普”。

This is a recommendation for when you have no constraints or better ideas. This rule was added after many requests for guidance.

当您没有约束或更好的选择时,可以考虑这个个建议。此规则可以在许多准则之后适用。

Example(示例)

struct Cable { int x; // ...};double foo(int x){ if (0 < x) { // ... } switch (x) { case 0: // ... break; case amazing: // ... break; default: // ... break; } if (0 < x) ++x; if (x < 0) something(); else something_else(); return some_value;}

Note the space between if and (

注意if和(之间的空格

Note(注意)

Use separate lines for each statement, the branches of an if, and the body of a for.

对于每个语句,if的分支和for的正文使用单独的行。

Note(注意)

The { for a class and a struct is not on a separate line, but the { for a function is.

类和结构的{不在单独的行上,而函数的{是。

Note(注意)

Capitalize the names of your user-defined types to distinguish them from standards-library types.

大写用户定义类型的名称,以将其与标准库类型区分开。

Note(注意)

Do not capitalize function names.

不要大写函数名称。

Enforcement(实施建议)

If you want enforcement, use an IDE to reformat.

如果要强制执行,请使用IDE重新格式化。

面向对象开发,面向对象思考!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:自学鸿蒙应用开发(30)- 自定义UI组件(1)
下一篇:EA&UML日拱一卒-多任务编程超入门-(1) 什么是多任务
相关文章

 发表评论

暂时没有评论,来抢沙发吧~