Item 1: View C++ as a federation of languages(Effective C++)
2009-11-10 21:39
357 查看
The easiest way is to view C++ not as a single language but as a federation of related languages. Within a particular sublanguage, the rules tend to be simple, straightforward, and easy to remember. When you move from one sublanguage to another, however, the rules may change. To make sense of C++, you have to recognize its primary sublanguages. Fortunately, there are only four:
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 , 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.
Object-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.
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. In fact, templates are so powerful, they give rise to a completely new programming paradigm, template metaprogramming (TMP).
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.
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 , 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.
Object-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.
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. In fact, templates are so powerful, they give rise to a completely new programming paradigm, template metaprogramming (TMP).
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.
相关文章推荐
- Effective C++ Item 1:View C++ as a federation of languages
- effective C++ Item 1: View C++ as a federation of languages
- Item 01 : View C++ as a federation of languages.
- Effective C++,rule 1,View C++ as a federation of languages
- Effective C++阅读笔记(2)Item 1: View C++ as a federation of languages
- Effective C++:Item 1: View C++ as a federation of languages
- Effective C++ -- Item 1: View c++ as a federation of languages
- Item 01: View C++ as a federation of languages
- 条款01:视C++为一个语言联邦(View C++ as a federation of languages)
- effective C++ 1 view c++ as a federation of languages
- 1.视C++为一个语言联邦 -- View C++ as a federation of languages
- 笔记:View C++ as a federation of language
- 读书笔记 effective c++ Item 38 通过组合(composition)为 “has-a”或者“is-implemented-in-terms-of”建模
- Effective C++ Item 12 Copy all parts of an object
- Effective C++ Item 19 Treat class design as type design
- read Item 25 of《More Effective C++》
- Effective C++ Item 38 通过复合塑模出 has-a 或 is-implemented-in-terms-of
- Effective C++ Item 38 通过复合塑模出 has-a 或 is-implemented-in-terms-of
- Effective C++ Item 34 Differentiate between inheritance of interface and inheritance of implementation
- <Effective Mordern C++>笔记:Item 4:Knowing how to view deduced types .