C++核心准则原文翻译

303 篇文章
31 人订阅

全部文章

面向对象思考

C++核心准则ES.60:避免在资源管理函数之外使用new和delete

Direct resource management in application code is error-prone and tedious.

7210
面向对象思考

C++核心准则ES.30: 不要使用宏进行程序中的文本操作​

ES.30: Don't use macros for program text manipulation

9310
面向对象思考

C++核心准则ES.32:宏定义名称全部大写

Convention. Readability. Distinguishing macros.

9420
面向对象思考

C++核心准则ES.47: 使用nullptr表现空指针,而不是0或NULL​

Readability. Minimize surprises: nullptr cannot be confused with an int. nullptr...

9420
面向对象思考

C++核心准则ES.27:使用std::array或者stack_array在堆栈上构建数组

They are readable and don't implicitly convert to pointers. They are not confuse...

7920
面向对象思考

C++核心准则ES.28: 使用lambda表达式进行变量的复杂初始化,特别是常量变量

It nicely encapsulates local initialization, including cleaning up scratch varia...

5830
面向对象思考

C++核心准则ES.31:不要用宏定义常量或函数​

Macros are a major source of bugs. Macros don't obey the usual scope and type ru...

7030
面向对象思考

C++核心准则ES.33:如果必须使用宏定义,命名要有唯一性

Avoid macros if you can: ES.30, ES.31, and ES.32. However, there are billions of...

10050
面向对象思考

C++核心准则ES.34:不要定义C风格的可变参数函数

Not type safe. Requires messy cast-and-macro-laden code to get working right.

8640
面向对象思考

C++核心准则ES.40:避免复杂的表达式

Some of these expressions are unconditionally bad (e.g., they rely on undefined ...

8070
面向对象思考

C++核心准则ES.41: 如果对操作符的优先级有疑问,使用括号明确运算次序

Avoid errors. Readability. Not everyone has the operator table memorized.

10360
面向对象思考

C++核心准则ES.42: 使用指针时要简单且直接

Complicated pointer manipulation is a major source of errors.

7120
面向对象思考

C++核心准则ES.44: 不要让执行结果受函数参数的求值次序影响​

ES.44: Don't depend on order of evaluation of function arguments

8750
面向对象思考

C++核心准则ES.45:避免“魔法常数”,使用符号化常量

Unnamed constants embedded in expressions are easily overlooked and often hard t...

9980
面向对象思考

C++核心准则ES.46:避免有损(窄化,截短)算数转换

A narrowing conversion destroys information, often unexpectedly so.

7530
面向对象思考

C++核心准则ES.43: 避免在表达式中使用无定义的运算次序

You have no idea what such code does. Portability. Even if it does something sen...

10020
面向对象思考

C++核心准则ES.26: 不要将一个变量用于两个无关的用途

As an optimization, you may want to reuse a buffer as a scratch pad, but even th...

11030
面向对象思考

C++核心准则ES.24: 使用unique_ptr<T>管理指针

Using std::unique_ptr is the simplest way to avoid leaks. It is reliable, it mak...

11041
面向对象思考

C++核心准则ES.23:优先使用{}​初始化器语法

Prefer {}. The rules for {} initialization are simpler, more general, less ambig...

12420
面向对象思考

C++核心准则ES.21: 不要在不需要时引入变量(或常量)

Readability. To limit the scope in which the variable can be used.

7920

扫码关注云+社区

领取腾讯云代金券