Effective C++【学习笔记】Item1

Chapter1 Accustoming yourself to C++

本书教导读者如何高效地使用C++编程,给读者提出了甚多有用的建议。在这些建议里,其中的一些比其他的更基础更重要。本章讲的就是这些最基础最重要的某些建议。

 

Item1

-----------------------------------------------------------------------------------------------------------------------------

Things to Remember

✦ Rules for effective C++ programming vary, depending on the part of C++ you are using.

-----------------------------------------------------------------------------------------------------------------------------

Item1: View C++ as a federation of languages.(语言联邦)

最开始,C++就是具有面向对象编程特征的C语言。随着C++的逐渐成熟,它变得越来越大胆越具有冒险性,采纳了各种与C语言不同且带有类的编程语言的想法,特征和编程策略。

Templates应运而生,STL也为扩展性定义了新的方法。

Today’s C++ is a multiparadigm(多范式) programming language, one supporting a combination of procedural, object-oriented, functional, generic, and metaprogramming features.

 

把C++看成是多种编程语言的联邦,而不是单纯的一门编程语言,这样的话,C++的编程规则就不再复杂:

Within a particular sublanguage, the rules tend to be simple, straightforward, and easy to remember.

 

规则在不同的子语言中会有变化,那么我们必须识别并牢记C++最基础的子语言的规则。

一共有四个sublanguages:

1. C;

Way down deep, C++ is still based on C. Blocks, statements, the preprocessor, built-in data types, arrays, pointers, etc., all come from C. In many cases, C++ offers approaches to problems that

are superior to their C counterparts (e.g., see Items 2 (alternatives to the preprocessor) and 13 (using objects to manage resources)), but when you find yourself working with the C part of C++, the rules for effective programming reflect C’s more limited scope: no templates, no exceptions, no overloading, etc.

 

2. Objected-Oriented C++;

This part of C++ is what C with Classes was all about: classes (including constructors and destructors), encapsulation, inheritance, polymorphism, virtual functions (dynamic binding), etc. This is the part of C++ to which the classic rules for object-oriented design most directly apply.

 

3. Template C++;

This is the generic programming part of C++, the one that most programmers have the least experience with. Template considerations pervade C++, and it’s not uncommon for rules

of good programming to include special template-only clauses (e.g., see Item 46 on facilitating type conversions in calls to template functions). In fact, templates are so powerful, they give rise

to a completely new programming paradigm, template metaprogramming (TMP). Item 48 provides an overview of TMP, but unless you’re a hard-core template junkie, you need not worry about it. The rules for TMP rarely interact with mainstream C++ programming.

 

4. The STL.

The STL is a template library, of course, but it’s a very special template library. Its conventions regarding containers, iterators, algorithms, and function objects mesh beautifully, but templates

and libraries can be built around other ideas, too. The STL has particular ways of doing things, and when you’re working with the STL, you need to be sure to follow its conventions.

 

Things to Remember

✦ Rules for effective C++ programming vary, depending on the part of C++ you are using.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值