1 Rules for the code in LyX
2 -------------------------
3 [updated from the C++STYLE distrubuted with the GNU C++ Standard]
5 The aim of this file is to serve as a guide for the developers, to aid us to
6 get clean and uniform code. Still uncomplete.
8 We really like to have new developers joining the LyX Project. However
9 since we have had problems in the past with developers leaving the
10 project and their contributed code in a far from perfect state. Most
11 of this happened before that we really became aware of these issues,
12 but still, we don't want it to happen again. So we have put together
13 some guidelines and rules for the developers.
15 In general, if you want to contribute to the main source, we expect at least
18 - write good C++ code: Readable, well commented and taking advantage of the
20 - adapt the code to the structures already existing in LyX, or in case that
21 you have better ideas, discuss them on the developer's list before writing
23 - take advantage of the C++ standard library.
25 These guidelines should save us a lot of work while cleaning up the code and
26 help us to have quality code. LyX has been haunted by problems coming from
27 unfinished projects by people who have left the team. Those problems will
28 hopefully disappear if the code is easy to hand over to somebody else.
30 When you send in a patch or commit to the LyX cvs repository we expect
31 you to add a ChangeLog entry. The entry should have this syntax:
33 1999-12-13 Lars Gullik Bjønnes <larsbj@lyx.org>
35 * src/support/lyxstring.C (find): assert bug fixed.
37 * Pointers and references
41 char *p = "flop"; // wrong
42 char &c = *p; // wrong
44 Some time ago we had a huge discusion on this subject and after
45 convincing argumentation from Asger this is what we decided. Also note
51 * Operator names and parentheses
54 operator == (type) // wrong
56 The == is part of the function name, separating it makes the
57 declaration look like an expression.
59 * Function names and parentheses
62 void mangle () // wrong
71 enum { one = 1, two = 2, three 3 };
73 * Naming rules for classes
75 - Use descriptive but simple and short names. For stuff specific to LyX
76 use LyX as prefix. Some modules, like mathed or spellchecker, could have
78 [I am not so sure about the LyX prefix]
80 - Class names are usually capitalized, and function names lowercased.
81 Enums are named like Classes, enum values in CAPS.
83 - Long variables are named like thisLongVariableName.
85 New types are capitalized, so this goes for typedefs,classes,structs
90 - Please adapt the formatting of your code to the setting in LyX in that
91 particular file. Lars and Asger are slowly, but surely moving the source
92 towards Linux kernel style formatting, aka K&R style. We suggest that you
93 also do this, but this is NOT something that has been decided generally.
96 * Use existing structures
98 - Use string whereever possible. LyX will someday move to Unicode, and
99 that will be easy if everybody uses string now.
101 - Check out the filename and path tools in filetools.h
103 - Check out the string tools in lstring.h, and the SubString class
106 - Use the DebugStream class to report errors and messages using
107 the lyxerr instantation.
109 [add description of other existing structures]
114 - Use this order for the access sections of your class: public,
115 protected, private. The public section is interesting for every
116 user of the class. The private section is only of interest for the
117 implementors of the class (you). [Obvously not true since this is
118 for developers, and we do not want one developer only to be able to
119 read and understand the implementation of class internals. Lgb]
121 - Avoid to declare global objects in the declaration file of the class.
122 If the same variable is used for all object, use a static member.
124 - Avoid global or static variables. An exception to this rule is
125 very private stuff like the math stack.
127 - Use the const keyword like this: char const * instead of const char *
128 because this is more logical.
133 - The documentation is generated from the header files.
134 - You document for the other developers, not for yourself.
135 - You should document what the funtion do, not the implementation.
136 - in the .C files you document the implementation.
137 - Single line description (///), multiple lines description (/** ... */)
138 - You make the documentation by doing "make srcdoc" in the root,
139 and then you'll find HTML in the srcdoc/ directory. Read with
140 Netscape for best results.
143 * NAMING RULES FOR USER-COMMANDS
145 Here's the set of rules to apply when a new command name is introduced:
147 1) Use the object.event order. That is, use `word-forward' instead of
149 2) Don't introduce an alias for an already named object. Same for events.
150 3) Forward movement or focus is called `forward' (not `right').
151 4) Backward movement or focus is called `backward' (not `left').
152 5) Upward movement of focus is called `up'.
153 6) Downward movement is called `down'.
154 7) The begin of an object is called `begin' (not `start').
155 8) The end of an object is called `end'.
158 * Using external GUI constructors (XForms fdesign)
160 - Fdesign generated files should not be changed at all. The only changes
161 needed are gettext, compability with 0.81 or when you have made your own
162 xforms objects and have just a dummy in the .fd file in place of your
163 own. In case you have to change the generated files for any of the
164 reasons above, you should provide a patch against the clean generated
165 file. Your callbacks must be in a separate file.