Dr. Bjarne Stroustrup (BS) in THE C ++ Programming Language (Special Edition) Advice 2 (Excerpt)

zhaozj2021-02-16  51

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

Chapter 4 Types and Statements

1. Maintain a smaller role.

2. Do not use the same name in a scope and its peripheral scope.

3. Only a name is declared in a statement.

4. Let common and local names are shorter, so that uncommonly used and global names are relatively long.

5. Avoid watching a similar name.

6. Maintain a unified naming style.

7. Choose the name carefully, reflect its meaning and not reflect the implementation.

8. If the internal type used indicates a variable value, use TypedEf to define a meaningful name.

9. Use typedef to define synonyms, define new types with enumeration or classes.

10. I must describe a type (Inti-INT ") in each statement.

11. Avoid unnecessary assumptions about character values.

12. Avoid unnecessary assumptions about the integer size.

13. Avoid unnecessary assumptions about floating point types representation.

14. Priority uses ordinary int instead of short int or long int.

15. Prioritize Double instead of float or long double.

16. Priority uses ordinary char than Signed Char or unsigned char.

17. Avoid unnecessary assumptions about the size of the object.

18. Avoid unsigned arithmetic.

19. You should take questions to see from Signed to Unsigned, or from unsigned to Signed.

20. You should look at the conversion from floating point to integer.

twenty one. You should look at the transition to a small type, such as converting Int to Char.

Chapter 5

1. Avoid non-flat pointer arithmetic.

2. Beware, don't write over the boundaries of the array.

3. Try to use 0 instead of NULL.

4. Try to use Vector and Valarray, not an array of internal (C style).

5. Try to use String instead of the CHAR array ended with 0.

6. Try to use less common reference parameters.

7. Avoid VOID *, in addition to in some low-level code.

8. Avoid using non-flat text quantities ("Mysterious Number") in your code. Instead, various symbol constants should be defined and used.

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

New Post(0)