TC++PL阅读笔记

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:

  • Rationale: What kinds of problems is it designed to help solve? What principles underlie the design? What are the fundamental limitations?
  • Sepecification: What is its definition? The level of detail if chosenn for the expert programmer;
  • Examples: How cant it be used well by itself and in combination with other features? what are the key techniques and idioms? What are the implications for maintainability and performance?

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

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

  • direct mappings of built-in operations and types to hardware to provide efficient memory use and efficient low-level operations, and
  • affordable and flexible abstraction mechanisms to provide user-defined types with the same notational support, range of uses, and performance as built-in types.

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:

  • Procedural programming
  • Data abstraction: 用接口隐藏细节(abstract class)
  • Object-oriented programming: Class hierarchies provide run-time polymorphism and encapsulation.
  • Generic programming: Template,

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++提供了两种抽象机制:“类”和“模板”

  • 具体类:The basic idea of concrete classes is that they behave "just like built-in types." The defining characteristic of a concrete type is that its representation is part of its definition.
  • 抽象类:An abstract type is a type that completely insulates a user from implementation details. A class that provides the interface to a variety of other classes is often called a polymorphic type.

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

面向对象编程

泛型编程

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,293评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,604评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,958评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,729评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,719评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,630评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,000评论 3 397
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,665评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,909评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,646评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,726评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,400评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,986评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,959评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,197评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,996评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,481评论 2 342

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,363评论 0 23
  • 越长大就越懂事,越懂事就越有故事 我一直想做个深有感触而不发的人,可这个时候想在简书上发泄发泄 一个女人想做成一件...
    焕语阅读 421评论 0 0
  • 【引子】 老人在村民们的指责下,气得沉着脸将白狗拴在石碾子上,随手从门后操起一根棍子举着就抡。白狗哦儿哦儿的叫着,...
    民间故事计划阅读 2,104评论 0 0
  • 思维是人做事的分析判断逻辑,讲究是非对错,或者说是哪个更好和哪个更差。 心理是人的心性活动,受意识和潜意识支配,意...
    鹤一张阅读 227评论 0 0