3 CodingStyle - standards while programming for GNU LilyPond
7 We 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 string 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.
44 ".cc" Implementation files
45 ".icc" Inline definition files
46 ".tcc" non inline Template defs
51 (append '(("\\.make$" . makefile-mode)
53 ("\\.icc$" . c++-mode)
54 ("\\.tcc$" . c++-mode)
56 ("\\.pod$" . text-mode)
61 The class Class_name_abbreviation is coded in F<class-name-abbr.*>
69 (add-hook 'c-mode-hook
70 '(lambda ()(setq c-basic-offset 4)))
73 (add-hook 'c++-mode-hook
74 '(lambda() (c-set-style "Stroustrup")
78 If you like using font-lock, you can also add this to your F<.emacs>:
80 (setq font-lock-maximum-decoration t)
81 (setq c++-font-lock-keywords-3
83 c++-font-lock-keywords-3
84 '(("\\b\\([a-zA-Z_]+_\\)\\b" 1 font-lock-variable-name-face)
85 ("\\b\\([A-Z]+[a-z_]+\\)\\b" 1 font-lock-type-face))
88 =head2 CLASSES and TYPES:
91 AClass_name (for Abbreviation_class_name)
96 Type Class::member_type_
97 Type Class::member_type()
99 the C<type> is a Hungarian notation postfix for C<Type>. See below
103 Macros should be written completely in uppercase
105 The code should not be compilable if proper macro declarations are not
108 Don't laugh. It took us a whole evening/night to figure out one of
113 Broken code (hardwired dependencies, hardwired constants, slow
114 algorithms and obvious limitations) should be marked as such:
115 either with a verbose TODO, or with a short "ugh" comment.
119 The source is commented in the DOC++ style. Check out doc++ at
120 http://www.zib.de/Visual/software/doc++/index.html
123 C style comments for multiline comments.
124 They come before the thing to document.
131 Long class documentation.
134 TODO Fix boring_member()
146 short memo. long doco of member()
147 @param description of arguments
150 Rettype member(Argtype);
154 data_member_ = 121; // ugh
160 Unfortunately most of the code isn't really documented that good.
167 ///check that *this satisfies its invariants, abort if not.
170 /// print *this (and substructures) to debugging log
174 protected member. Usually invoked by non-virtual XXXX()
178 /**add some data to *this.
179 Presence of these methods usually imply that it is not feasible to this
184 /// replace some data of *this
189 Every class should have a default constructor.
191 Don't use non-default constructors if this can be avoided:
195 is less readable than
201 Foo f(Foo_convert::int_to_foo (1))
205 =head1 HUNGARIAN NOTATION NAMING CONVENTION
207 Proposed is a naming convention derived from the so-called I<Hungarian
212 The Hungarian Notation was conceived by or at least got its name from,
213 the hungarian programmer Charles Simonyi. It is a naming convention
214 with the aim to make code more readable (for fellow programmers), and
215 more accessible for programmers that are new to a project.
217 The essence of the Hungarian Notation is that every identifier has a
218 part which identifies its type (for functions this is the result
219 type). This is particularly useful in object oriented programming,
220 where a particular object implies a specific interface (a set of
221 member functions, perhaps some redefined operators), and for
222 accounting heap allocated memory pointers and links.
226 Another fun quote from Microsoft Secrets:
229 The Hungarian naming convention gives developers the ability
230 to read other people's code relatively easily, with a minmum
231 number of comments in the source code. Jon De Vann estimated
232 that only about 1 percent of all lines in the Excel product
233 code consist of comments, but the code is still very
234 understandable due to the use of Hungarian: "if you look at
235 our source code, you also notice very few comments. Hungarian
236 gives us the ability to go in and read code..."
238 Wow! If you use Hungarian you don't have to document your software!
239 Just think of the hours I have wasted documenting while this "silver bullet"
240 existed. I feel so stupid and ashamed! [Didn't MMM-Brooks say `There is
241 no silver bullet?' --HWN]
250 more keystrokes (disk space!)
254 it looks silly C<get_slu_p()>
258 it looks like code from micro suckers
262 (which) might scare away some (otherwise good?)
263 progammers, or make you a paria in the free
272 not very useful if not used consistently
276 usefullness in I<very large> (but how many classes is very large?)
289 learn about cut and paste / use emacs or vi
290 or lean to type using ten fingers
294 Use emacs dabbrev-expand, with dabbrev-case-fold-search set to nil.
298 use no, or pick less silly, abbrvs.
302 use non-ambiguous postfixes C<identifier_name_type_modifier[_modifier]>
306 Macros, C<enum>s and C<const>s are all uppercase,
307 with the parts of the names separated by underscores.
316 unsigned char. (The postfix _by is ambiguous)
345 Zero terminated c string
353 =head2 User defined types
360 Slur* slur_p = new Slur;
364 The following types modify the meaning of the prefix.
365 These are preceded by the prefixes:
379 const. Note that the proper order is C<Type const> i.s.o. C<const Type>
383 A const pointer. This would be equivalent to C<_c_l>, but since any
384 "const" pointer has to be a link (you can't delete a const pointer),
389 temporary pointer to object (link)
393 pointer to newed object
405 Variable loop: an integer
409 Temporary variable: an unsigned integer
413 Variable test: a character
415 =item C<first_name_str>
417 Variable first_name: a String class object
419 =item C<last_name_ch_a>
421 Variable last_name: a C<char> array
425 Variable foo: an C<Int*> that you must delete
429 Variable bar: an C<Int*> that you must not delete
433 Generally default arguments are taboo, except for nil pointers.
437 For some tasks, some scripts are supplied, notably creating patches, a
438 mirror of the website, generating the header to put over cc and hh
439 files, doing a release.
443 The following generic identifications are used:
450 Intervals are pictured lying on a horizontal numberline (Interval[-1]
451 is the minimum). The 2D plane has +x on the right, +y pointing up.