The C++ Programming Language笔记

读书计划: 英文版 867pages / 20 pages = 40

2011.11.02 (1-30)

Chaper 1 notes to reader

本书侧重程序的组织而不是写算法,专注在语言特征,基本的程序组成技术和组成规则。语言和库特征多会通过上下文实例来讲解,而不是枯燥的手册。 另一本作者与人合作的书,The Annotated C++ Standard Library. 练习分难度的,*n,n越大,需要的时间越长。 在第一部分,C程序书有帮助,二三部分,数据结构域算法会有帮助。

讲述的内容是纯C++,学习的时候关注概念,不要陷入语言技术细节。如同学会任何一门语言或乐器,学习C++也需要时间和练习。没有必要一定先学C,直接学C++就可以。 如果想游泳,一个语言特征必须优雅简洁,并且在实际程序中代价是可支付的。

C++设计使大的程序能保持良好的结构,让个人能处理大量的代码。C++拥有有效直接操纵硬件的功能,无需考虑安全性和易懂性。一个编程语言通常有两个目的,给程序员提供一系列执行actions,给程序员提供一组概念,考虑什么可以做。

C++借鉴了很多其它语言的特征。 论述了一大段C和C++关系,没仔细看。 有一句,好的c程序,一般tend to be C++ programs. 提到The C programming language.


给C程序员的建议:

越懂C,越可能写C风格的C++,发挥不了C++特性,C++与C有很多不同,C++的实现更安全好用。几个重要方面。


用C++思考编程:

分析问题-》关键概念设计求解-》将解表达成程序

写好程序的关键,是设计类表达一个单一概念。关注问题,比如 这个类如何创建? 这个类可以复制或销毁吗? 什么操作可以作用在这个类? 如果没有好的答案,这个概念可能并不清楚。

一个概念不会独立存在于空白,相关概念的类总是聚集在一起的。 层次结构是最好的管理工具。c++的derived lass可以很好的表达这一类结构,一个程序组织成树几何或有向无环图。 虚函数~有些概念可能相互依赖,除非能容易的定义基本概念的关系,程序将变得难以管理。 另一个处理依赖图的工具是将interface 和实现分开。 用末班表达通用性,而不是集成。

记住大多数程序可以简洁清晰的,使用基本类型、数据结构、普通函数和一些库类实现。


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 two answers:"Know what you want to say" and "practice". "Imitate good writing." Both appear to be as appropriate for C++ as they are for English and as hard to follow.


Advice

To write a good program takes intelligence, taste and patience. You are not going to get it right the first time. Experiment!

[1] when you program, you create a concrete representation of the ideas in your solution to some problem. let the structure of the program reflect those ideas as directly as possible:

if you can think of it as a separate idea, make it a class.

if you can think of it as a separate entity, make it an object of some class

if two classes have a common interface, make that interface an abstract class.

if the implementations of two classes have something significant in common, make that commonality a base class.

if a class is a container of objects, make it template.

if a function implements an algorithm for a container, make it a template function implementing the algorithm for a family of containers.

if a set of classes, templates, etc., are logically related, place them in a common namespace.

[2] when you define either a class that does not implement a mathematical entity like a matrix or a complex number or a low-level type such as a linked list:

don't use global data.

don't use global functions.

don't use public data members.

don't use friends, except to a void [a] or [c].

don't put a "type field" in a class; use virtual functions.

don't use inline functions, except as a significant optimization.


Chapter 2 A Tour of C++

2.1 what is C++?

C++ is a general-purpose programming language with a bias towards systems programming that

-is a better C,

-supports data abstraction,

-supports object-oriented programming, and

-supports generic programming.

2.2 Programming Paradigms

语言support和enable某种语言特性的区别。 convenient or takes exceptional effort

The important issue is not so much what features a languange possesses, but the features it does possess are sufficient to support the desired programming styles in the desired applications areass:

aesthetics and logic, what you don't know won't hurt you.

2.3 Procedural Programming

 

2.4 模块程序设计

确定你需要哪些模块;将程序分为一些模块,使数据隐藏于模块之中。 这一范型也被作为数据隐藏原理而广为人知。在那些不存在与数据相关的过程组之处,采用这种过程式程序设计就足够了。C++提供了一种机制,可以把相关的数据、函数等组织到一个独立的名字空间里。

 

2.5 数据抽象

抽象类型-界面与表示的完全分离,放弃真正的局部变量。使用虚函数定义界面,未另外一些不同的类提供界面的类也常被称作多态类型

虚函数 正确的解析函数定义,一种常用实现技术是让编译器把一个virtual函数的名字转换为指向这些函数的指针表的一个下标, 虚函数表vtbl。 空间开销是带有虚函数的类的每个对象包含一个指针,而每个这样的类需要一个vtbl。

2.6 面向对象的程序设计

Shape – Circle Rectangle Square

区分所有形状的共有特征,与某个特定形状种类的特殊特征,表达这种区分并由此获益的就定义了面向对象的程序设计。

现在程序设计泛型:确定你需要哪些类;为每个类提供完整的一组操作;利用继承去明确的表示共性。

2.7通用程序设计

设计泛型: 确定你需要哪些算法;将他们参数化,使他们能够对各种各样适当的类型和数据结构工作。

2.9 忠告

不用害怕,一切都会随着时间的推移而逐渐明朗起来;

你并不需要在知道了C++的所有细节之后才能写出好的C++程序;

请特别关注程序设计技术,而不是各种语言特征;

第3章 标准库概览

 

一些基本的介绍关于标准库。

下次起始页:51

 



posted @ 2011-11-03 00:20  wonderlily  阅读(236)  评论(0编辑  收藏  举报