C + + Programming specification 101 rules

Source: Internet
Author: User
Tags version control system

A long time has not updated the blog, in fact, no matter how busy, sometimes write blog is not a promotion. Here is some of the book I read recently.

1. Do not ignore the warning, try not to warn.

2. Using the Automatic build system

3. Using the version control system

4. Invest in Code review

5. An entity should have only one compact responsibility

6. Correct, simple and clear code.

7. Programming should know when and how to consider scalability

8. Do not perform immature optimizations.

9. Do not make premature deterioration.

10. Minimize global and shared data.

11. Hide the information.

12. Know when and how to do concurrent programming.

13. Make sure that the resource is owned by the object, using explicit Rall and smart pointers.

14. Prefer compile-time and connection-time errors, and do not run errors.

15. Actively use Const.

16. Avoid using macros.

17. Avoid using magic numbers.

18. Declare variables as locally as possible.

19. Always initialize variables.

20. Avoid the nesting process by avoiding the function too long.

21. Avoid initialization dependencies across compilation units.

22. Minimize the definition of dependency and avoid cyclic dependence.

23. The header file should be self-sufficient.

24. Always write an internal # include protector, never write an external # include protector.

25. Correctly select pass parameters by value, pointer, or reference.

26. Keep the natural semantics of overloaded operators.

27. Use the standard form of the arithmetic operator and the assignment operator preferentially.

28. Preferential use of + + and--standard form, limited call prefix form.

29. Consider overloading to avoid implicit type conversions.

30. Heavy-Duty &&,| | Or, (comma).

31. Do not write code that relies on the order of the function parameter evaluation.

32. Find out what kind of writing you are going to write.

33. Replace the giant class with a small class.

34. Replace inheritance with a combination.

35. Avoid inheriting from classes that are not designed to be base classes.

36. Give preference to abstract interfaces.

37. Public inheritance can be substituted. Inheritance, not for reuse. But to be reused.

38. Implement a security rewrite.

39. Consider declaring a virtual function as non-public and declaring the public function non-virtual.

40. To avoid providing an implicit conversion.

41. Set data members to private, no behavior aggregation (struct in C language).

42. Do not disclose internal data.

43. Use Pimpl explicitly. (Make private members truly invisible).

44. Prioritize non-member non-friend functions.

45. Always provide new and delete together.

46. If you provide class-specific new, you should provide all standard forms (normal, in-place and non-throwing).

47. Define and initialize member variables in the same order.

48. Initialize in constructor instead of assignment.

49. Avoid calling virtual functions in constructors and destructors.

50. Set the base class destructor to be public and virtual, or protected and non-virtual.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.