TC++PL阅读笔记

2017-03-09  本文已影响0人  GradientDescent

2017.03
Bjarne Stroustrup. The C++ Programming Language. 4ed, Person Education, Inc. 2013

笔记思路

笔记的目的是帮助阅读中的理解和遗忘后回顾,主要是给自己看。

前言部分

本书内容和写作方式

本书厚达一千三百多页,目的是 completeness,用Stroustrup大神的原话:

I describe every language feature and standard-library component that a professional programmer is likely to need. For each, I provide:

所以阅读的过程中也要按这个结构去看每一部分内容, 才能理解的更好理快。

C++是一个什么样的语言?

C++ is a general-purpose programming language emphasizing the design and use of type-rich, lightweight abstractions. It is particularly suited for resource-constrained applications, such as those found in software infrastructures.

Part I Introduction

Overview of the major concepts and features and its standard library.

The Design of C++

C++ is based on the idea of providing both

The design of C++ has focused on programming techniques dealing with fundamental notions such as memory, mutability, abstraction, resource management, expression of algorithms, error handling, and modularity. Those are the most import concerns of a systems programmer and more generally of programmers of resource-constrained and high-performance systems.

C++ support four programming styles:

The notion of static types and compile-time type checking is central to effective use of C++. It prevents accidental corruption of data, C++ protects against accident, not against fraud.

相比于C, Dennis Ritchie said "C is a strongly typed, weekly checked language."

Learning C++

Language features exist to support a variety of programming styles and techniques. Consequently, the task of learning a language should focus on mastering the native and natural styles for that language - not on understanding of every little detail of every language feature. Writing programs is essential.

Fundamental application concepts are represented as abstraction(e.g., classes, templates, and class hierarchies) in libraries. Many of the most fundamental programming concepts are represented in the standard library. Thus, learning the standard library is an integral part of learning C++. The standard library is the repository of much hard-earned knowledge of how to use C++ well.

The most important thing to do when learning C++ is to focus on fundamental concepts (such as type safety, resource management, and invariants) and programming techniques (such as resource management using scoped objects and the use of iterators in algorithms) and not get lost in language-technical details.

The question "How does one write good programs in C++?" is very similar to the question "How does one write good English prose?" There are tow answers: "Know what you want to say" and "Practice. Imitate good writing."

Invariants

A statement of what is assumed to be true for a class is called a class invariant, or simply an invariant (e.g. "class member elem points to an array of sz doubles").

The notion of invariants underlies C++'s notions of resource management supported by constructors and destructors.

另外还可以参考 loop invariant 的概念.

简述 C++ 的抽象机制

C++提供了两种抽象机制:“类”和“模板”

RAII: The technique of acquiring resources in a constructor and releasing them in a destructor, known as Resource Acquisition Is Initialization or RAII, allows us to eliminate "naked new operations"

模板

仿函数

Part II Basic Facilities

Part III Abstractions Mechanisms

面向对象编程

泛型编程

上一篇 下一篇

猜你喜欢

热点阅读