3 CodingStyle - standards while programming for LilyPond
7 Please use these standards while doing programming for LilyPond
9 Functions and methods do not return errorcodes, but use assert for
12 A program should be light and agile, its subroutines
13 connected like a strings of pearls. The spirit and intent of
14 the program should be retained throughout. There should be
15 neither too little nor too much, neither needless loops nor
16 useless variables, neither lack of structure nor overwhelming
19 A program should follow the 'Law of Least
20 Astonishment'. What is this law? It is simply that the
21 program should always respond to the user in the way that
24 A program, no matter how complex, should act as a
25 single unit. The program should be directed by the logic
26 within rather than by outward appearances.
28 If the program fails in these requirements, it will be
29 in a state of disorder and confusion. The only way to correct
30 this is to rewrite the program.
31 -- Geoffrey James, "The Tao of Programming"
38 (add-hook 'c-mode-hook
39 '(lambda ()(setq c-basic-offset 4)))
42 (add-hook 'c++-mode-hook
43 '(lambda() (c-set-style "Stroustrup")
48 =head2 CLASSES and TYPES:
51 AClass_name (for Abbreviation_class_name)
56 Type Class::member_type_
58 the C<type> is a Hungarian notation postfix for $C<Type>$. See below
63 The source is commented in the DOC++ style. Check out doc++ at
64 http://www.zib.de/Visual/software/doc++/index.html
67 C style comments for multiline comments.
74 Long class documentation.
87 short memo. long doco of member()
88 @param description of arguments
91 Rettype member(Argtype);
97 Unfortunately most of the code isn't really documented that good.
100 =head2 CLASSNAMES (2)
102 A lot of classes in LilyPond start with 'P', this is to distinguish
103 certain parts of LilyPond: the P stands for Printer, and the P-classes
104 are supposed to be more lowlevel than the others. Example:
106 Staff uses PStaff, PScore and PCol to do the typesetting of
107 symbols. Staff is the "brains" for PStaff
109 NB: in PCursor (which is part of the library) P stands for PointerCursor
116 ///check that *this satisfies its invariants, abort if not.
119 /// print *this (and substructures) to debugging log
123 protected member. Usually invoked by non-virtual XXXX()
127 /**add some data to *this.
128 Presence of these methods usually imply that it is not feasible to this
133 /// replace some data of *this
136 =head1 HUNGARIAN NOTATION NAMING CONVENTION
138 Proposed is a naming convention derived from the so-called I<Hungarian
143 The Hungarian Notation was conceived by or at least got its name from,
144 the hungarian programmer Charles Simonyi. It is a naming convention
145 with the aim to make code more readable (for fellow programmers), and
146 more accessible for programmers that are new to a project.
148 The essence of the Hungarian Notation is that every identifier has a
149 part which identifies its type (for functions this is the result
150 type). This is particularly useful in object oriented programming,
151 where a particular object implies a specific interface (a set of
152 member functions, perhaps some redefined operators), and for
153 accounting heap allocated memory pointers and links.
157 Another fun quote from Microsoft Secrets:
160 The Hungarian naming convention gives developers the ability
161 to read other people's code relatively easily, with a minmum
162 number of comments in the source code. Jon De Vann estimated
163 that only about 1 percent of all lines in the Excel product
164 code consist of comments, but the code is still very
165 understandable due to the use of Hungarian: "if you look at
166 our source code, you also notice very few comments. Hungarian
167 gives us the ability to go in and read code..."
170 Wow! If you use Hungarian you don't have to document your software!
171 Just think of the hours I have wasted documenting while this "silver bullet"
172 existed. I feel so stupid and ashamed!
179 more keystrokes (disk space!)
182 it looks silly C<get_slu_p()>
185 it looks like code from micro suckers
188 (which) might scare away some (otherwise good?)
189 progammers, or make you a paria in the free
196 not very useful if not used consistently
199 usefullness in I<very large>
200 (but how many classes is very large?)
212 learn about cut and paste / use emacs or vi
213 or lean to type using ten fingers
216 Use emacs dabbrev-expand, with dabbrev-case-fold-search set to nil.
219 use no, or pick less silly, abbrvs.
222 use non-ambiguous postfixes C<identifier_name_type_modifier[_modifier]>
225 Macros, C<enum>s and C<const>s are all uppercase,
226 with the parts of the names separated by underscores.
233 unsigned char. (The postfix _by is ambiguous)
254 Zero terminated c string
261 =head2 User defined types
268 Slur* slur_p = new Slur;
272 The following types modify the meaning of the prefix.
273 These are precede the prefixes:
287 temporary pointer to object (link)
290 pointer to newed object
300 Variable loop: an integer
303 Temporary variable: an unsigned integer
306 Variable test: a character
308 =item C<first_name_str>
309 Variable first_name: a String class object
311 =item C<last_name_ch_a>
312 Variable last_name: a C<char> array
315 Variable foo: an C<Int*> that you must delete
318 Variable bar: an C<Int*> that you must not delete