]> git.lyx.org Git - lyx.git/blob - development/Code_rules/Recommendations
spec patch from Kayvan
[lyx.git] / development / Code_rules / Recommendations
1 These are some rules for effective C++ programming. These are taken from 
2 Scott Meyers, and are presented in their short form. These are not all the 
3 rules Meyers presents, only the most important of them. LyX does not yet 
4 follow these rules, but they should be the goal.
5
6 - Use const and inline instead of #define
7
8 - Use the same form in corresponding calls to new and delete,
9   i.e. write delete[] obj; if new obj[n]; was used to create
10   the object and write delete obj; if you wrote new obj;
11   Notice strings should be std::string's instead of char *'s.
12
13 - Define a default constructor, copy constructor and an assignment
14   operator for all classes with dynamically allocated memory that
15   do not inherit noncopyable
16
17 - make destructors virtual in base classes.
18
19 - assign to all data members in operator=.
20
21 - strive for class interfaces that are complete and minimal
22
23 - differentiate among member functions, global functions and friend
24   functions.
25
26 - avoid data members in the public interface.
27
28 - use const whenever possible
29
30 - pass and return objects by reference instead of by value
31
32 - choose carefully between function overloading and
33   parameter defaulting.
34
35 - never return a reference to a local object or a dereferenced
36   pointer initialized by new within the function.
37
38 - use enums for integral constants.
39
40 - minimize compilation dependencies between files.
41
42 - pay attention to compiler warnings
43
44 - differentiate between inheritance of interface and
45   inheritance of implementation.
46
47 - differentiate between inheritance and templates
48
49 - know what functions C++ silently writes and calls.
50
51 - ensure that global objects are initialized before they are used.
52
53 - avoid conditions to 'if' and 'while' that span more than a line
54
55 --------
56
57 S. Meyers. Effective C++, 50 Specific Ways to Improve Your Programs and 
58 Design. Addison-Wesley, 1992
59
60 ==================================
61
62 And one of mine: (Lgb)
63
64 - When swiching on enums, refrain from using "default:" if possible.
65
66