Dr. Bjarne Stroustrup (BS) In THE C ++ Programming Language (Special Edition) 1 (extracted)

zhaozj2021-02-16  47

Dr. Bjarne Stroustrup (BS) in The C Programming Language (Special Edition) Advice (Excerpt)

Chapter 1 to the reader

1. When programming, you are a specific representation in the idea of ​​your solution for a problem. Let the structure of the program directly reflect these ideas as much as possible:

a. If you can see "it" as an independent concept, make it a class.

b. If you can see "it" as a separate entity, do it into an object of a class.

c. If two classes have a common interface, make this interface into an abstract class.

d. If the implementation of the two classes has some significant common things, these commonarities are made into a base class.

e. If a class is an object's container, make it a template.

f. If a function implements an algorithm for a container, do it into a template function available to a group container.

g. If a set of classes, templates, etc., have logical contacts, put them in a name space.

2. When you define a class that doesn't implement a mathematical object such as a matrix or multiplex, or define a low-level type such as a link table:

a. Do not use global data (using members).

b. Do not use global functions.

c. Do not use public data members.

d. Do not use friends unless A or C is avoided.

e. Do not place "Type Domain" in a class (refer to the flag domain that is placed in order to illustrate the data stored in the data; use the virtual function.

f. Do not use the online function, unless the effect is remarkable.

Chapter 2 C Overview

1. Don't be afraid, everything will gradually beat over time.

2. You don't need to write a good C program after all the details of C .

3. Please pay special attention to program design technology, not a variety of language characteristics.

Chapter 3 Standard Library Overview

1. Don't try to do everything as you reinvent the wheel; go to the library.

2. Don't believe in miracles; understand what your library can do, how do they do, how much cost is needed?

3. When you encounter a choice, you should prefer a standard library instead of other libraries.

4. Don't think that the standard library is ideal for anything.

5. Remember the header file of #include you used.

6. Remember, the functionality of the standard library is defined in the namespace STD.

7. Please use String instead of char *.

8. If doubt, use a vector (for example, VEC) with a check interval range.

9. Vector , List and MAP are better than T [].

10. If you add an element to a container, use push_back () or back_inserter ().

11. Use Push_BACK () to Vector, not the regalog to Realloc ().

12. Capture public abnormalities in main ().

转载请注明原文地址:https://www.9cbs.com/read-25886.html

New Post(0)