本文共 1933 字,大约阅读时间需要 6 分钟。
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重新格式化。
原文链接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl17-use-kr-derived-layout
新书介绍
是作者最近出版的新书,拜托多多关注!
本书利用Python 的标准GUI 工具包tkinter,通过可执行的示例对23 个设计模式逐个进行说明。这样一方面可以使读者了解真实的软件开发工作中每个设计模式的运用场景和想要解决的问题;另一方面通过对这些问题的解决过程进行说明,让读者明白在编写代码时如何判断使用设计模式的利弊,并合理运用设计模式。
对设计模式感兴趣而且希望随学随用的读者通过本书可以快速跨越从理解到运用的门槛;希望学习Python GUI 编程的读者可以将本书中的示例作为设计和开发的参考;使用Python 语言进行图像分析、数据处理工作的读者可以直接以本书中的示例为基础,迅速构建自己的系统架构。
觉得本文有帮助?请分享给更多人。
关注微信公众号【面向对象思考】轻松学习每一天!
面向对象开发,面向对象思考!
转载地址:https://oothinking.blog.csdn.net/article/details/115218302 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!