3 CodingStyle - standards while programming for GNU LilyPond
7 Please use these standards while doing programming for GNU LilyPond
9 Functions and methods do not return errorcodes, but use assert for
14 A program should be light and agile, its subroutines
15 connected like a strings of pearls. The spirit and intent of
16 the program should be retained throughout. There should be
17 neither too little nor too much, neither needless loops nor
18 useless variables, neither lack of structure nor overwhelming
21 A program should follow the 'Law of Least
22 Astonishment'. What is this law? It is simply that the
23 program should always respond to the user in the way that
26 A program, no matter how complex, should act as a
27 single unit. The program should be directed by the logic
28 within rather than by outward appearances.
30 If the program fails in these requirements, it will be
31 in a state of disorder and confusion. The only way to correct
32 this is to rewrite the program.
34 -- Geoffrey James, "The Tao of Programming"
38 Definitions of classes that are only accessed via pointers
39 (*) or references (&) shall not be included as include files.
41 Include files in C++ always have the file name extension ".hh".
43 Implementation files in C++ always have the file name
46 Inline definition files always have the file name extension ".icc".
54 (add-hook 'c-mode-hook
55 '(lambda ()(setq c-basic-offset 4)))
58 (add-hook 'c++-mode-hook
59 '(lambda() (c-set-style "Stroustrup")
64 =head2 CLASSES and TYPES:
67 AClass_name (for Abbreviation_class_name)
72 Type Class::member_type_
74 the C<type> is a Hungarian notation postfix for C<Type>. See below
79 The source is commented in the DOC++ style. Check out doc++ at
80 http://www.zib.de/Visual/software/doc++/index.html
83 C style comments for multiline comments.
84 They come before the thing to document.
91 Long class documentation.
104 short memo. long doco of member()
105 @param description of arguments
108 Rettype member(Argtype);
114 Unfortunately most of the code isn't really documented that good.
117 =head2 CLASSNAMES (2)
119 A lot of classes in GNU LilyPond start with 'P', this is to distinguish
120 certain parts of GNU LilyPond: the P stands for Printer, and the P-classes
121 are supposed to be more lowlevel than the others. Example:
123 Staff uses PStaff, PScore and PCol to do the typesetting of
124 symbols. Staff is the "brains" for PStaff
126 NB: in PCursor (which is part of the library) P stands for PointerCursor
133 ///check that *this satisfies its invariants, abort if not.
136 /// print *this (and substructures) to debugging log
140 protected member. Usually invoked by non-virtual XXXX()
144 /**add some data to *this.
145 Presence of these methods usually imply that it is not feasible to this
150 /// replace some data of *this
153 =head1 HUNGARIAN NOTATION NAMING CONVENTION
155 Proposed is a naming convention derived from the so-called I<Hungarian
160 The Hungarian Notation was conceived by or at least got its name from,
161 the hungarian programmer Charles Simonyi. It is a naming convention
162 with the aim to make code more readable (for fellow programmers), and
163 more accessible for programmers that are new to a project.
165 The essence of the Hungarian Notation is that every identifier has a
166 part which identifies its type (for functions this is the result
167 type). This is particularly useful in object oriented programming,
168 where a particular object implies a specific interface (a set of
169 member functions, perhaps some redefined operators), and for
170 accounting heap allocated memory pointers and links.
174 Another fun quote from Microsoft Secrets:
177 The Hungarian naming convention gives developers the ability
178 to read other people's code relatively easily, with a minmum
179 number of comments in the source code. Jon De Vann estimated
180 that only about 1 percent of all lines in the Excel product
181 code consist of comments, but the code is still very
182 understandable due to the use of Hungarian: "if you look at
183 our source code, you also notice very few comments. Hungarian
184 gives us the ability to go in and read code..."
187 Wow! If you use Hungarian you don't have to document your software!
188 Just think of the hours I have wasted documenting while this "silver bullet"
189 existed. I feel so stupid and ashamed!
197 more keystrokes (disk space!)
201 it looks silly C<get_slu_p()>
205 it looks like code from micro suckers
209 (which) might scare away some (otherwise good?)
210 progammers, or make you a paria in the free
219 not very useful if not used consistently
223 usefullness in I<very large>
224 (but how many classes is very large?)
237 learn about cut and paste / use emacs or vi
238 or lean to type using ten fingers
242 Use emacs dabbrev-expand, with dabbrev-case-fold-search set to nil.
246 use no, or pick less silly, abbrvs.
250 use non-ambiguous postfixes C<identifier_name_type_modifier[_modifier]>
254 Macros, C<enum>s and C<const>s are all uppercase,
255 with the parts of the names separated by underscores.
264 unsigned char. (The postfix _by is ambiguous)
293 Zero terminated c string
301 =head2 User defined types
308 Slur* slur_p = new Slur;
312 The following types modify the meaning of the prefix.
313 These are precede the prefixes:
327 const. Note that the proper order C<Type const> i.s.o. C<const Type>
331 A const pointer. This would be equivalent to C<_c_l>, but since any
332 "const" pointer has to be a link (you can't delete a const pointer),
337 temporary pointer to object (link)
341 pointer to newed object
353 Variable loop: an integer
357 Temporary variable: an unsigned integer
361 Variable test: a character
363 =item C<first_name_str>
365 Variable first_name: a String class object
367 =item C<last_name_ch_a>
369 Variable last_name: a C<char> array
373 Variable foo: an C<Int*> that you must delete
377 Variable bar: an C<Int*> that you must not delete
381 Generally default arguments are taboo, except for nil pointers.