mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 22:41:09 +00:00
fae43b38d0
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@24919 a592a061-630c-0410-9148-cb99ea01b6c8
73 lines
2.2 KiB
Plaintext
73 lines
2.2 KiB
Plaintext
These are some rules for effective C++ programming. These are taken from
|
|
Scott Meyers, and are presented in their short form. These are not all the
|
|
rules Meyers presents, only the most important of them. LyX does not yet
|
|
follow these rules, but they should be the goal.
|
|
|
|
- use const and inline instead of #define
|
|
|
|
- use the same form in corresponding calls to new and delete,
|
|
i.e. write delete[] obj; if new obj[n]; was used to create
|
|
the object and write delete obj; if you wrote new obj;
|
|
Notice strings should be std::string's instead of char *'s.
|
|
|
|
- define a default constructor, copy constructor and an assignment
|
|
operator for all classes with dynamically allocated memory that
|
|
are not made noncopyable
|
|
|
|
- do not define default constructor, copy constructor and an assignment
|
|
operator if the compiler generated one would do the same
|
|
|
|
- make destructors virtual in base classes and only there
|
|
|
|
- assign to all data members in operator=()
|
|
|
|
- strive for class interfaces that are complete and minimal
|
|
|
|
- differentiate among member functions, global functions and friend
|
|
functions
|
|
|
|
- avoid data members in the public interface
|
|
|
|
- use const whenever possible
|
|
|
|
- pass and return objects by reference instead of by value
|
|
|
|
- choose carefully between function overloading and
|
|
parameter defaulting
|
|
|
|
- never return a reference to a local object or a dereferenced
|
|
pointer initialized by new within the function
|
|
|
|
- use enums for integral constants
|
|
|
|
- minimize compilation dependencies between files
|
|
|
|
- pay attention to compiler warnings
|
|
|
|
- differentiate between inheritance of interface and
|
|
inheritance of implementation
|
|
|
|
- differentiate between inheritance and templates
|
|
|
|
- ensure that global objects are initialized before they are used
|
|
|
|
- avoid conditions to 'if' and 'while' that span more than a line
|
|
|
|
--------
|
|
|
|
S. Meyers. Effective C++, 50 Specific Ways to Improve Your Programs and
|
|
Design. Addison-Wesley, 1992
|
|
|
|
==================================
|
|
|
|
And one of mine: (Lgb)
|
|
|
|
- when swiching on enums, refrain from using "default:" if possible
|
|
|
|
|
|
And one of mine: (Andre')
|
|
|
|
- try to implement your class in a way that the automatically generated
|
|
copy constructor and copy assignment work out-of-the box
|
|
|