1 @c -*- coding: us-ascii; mode: texinfo; -*-
3 @chapter Programming work
6 * Introduction to programming::
11 @node Introduction to programming
12 @section Introduction to programming
19 @c email to wl@gnu.org when I get here.
24 @subsection Outputting errors
26 As a general rule, you should always try to continue computations,
27 even if there is some kind of error. When the program stops, it
28 is often very hard for a user to pinpoint what part of the input
29 causes an error. Finding the culprit is much easier if there is
32 So functions and methods do not return errorcodes, they never
33 crash, but report a programming_error and try to carry on.
37 C++ and Python are preferred. Python code should use PEP 8.
41 Definitions of classes that are only accessed via pointers (*) or
42 references (&) shall not be included as include files.
48 ".cc" Implementation files
49 ".icc" Inline definition files
50 ".tcc" non inline Template defs
55 (append '(("\\.make$" . makefile-mode)
57 ("\\.icc$" . c++-mode)
58 ("\\.tcc$" . c++-mode)
60 ("\\.pod$" . text-mode)
65 The class Class_name is coded in @q{class-name.*}
67 @subsection Indentation
69 Standard GNU coding style is used. In emacs:
72 (add-hook 'c++-mode-hook
73 '(lambda() (c-set-style "gnu")
77 If you like using font-lock, you can also add this to your
81 (setq font-lock-maximum-decoration t)
82 (setq c++-font-lock-keywords-3
84 c++-font-lock-keywords-3
85 '(("\\b\\(a-zA-Z_?+_\\)\\b" 1 font-lock-variable-name-face) ("\\b\\(A-Z?+a-z_?+\\)\\b" 1 font-lock-type-face))
90 @subsection Classes and Types
99 Member variable names end with an underscore:
108 Macro names should be written in uppercase completely.
111 @subsection Broken code
113 Do not write broken code. This includes hardwired dependencies,
114 hardwired constants, slow algorithms and obvious limitations. If
115 you can not avoid it, mark the place clearly, and add a comment
116 explaining shortcomings of the code.
118 We reject broken-in-advance on principle.
125 Messages need to follow Localization.
128 @subsection Localization
130 This document provides some guidelines for programmers write user
131 messages. To help translations, user messages must be
132 uniformized. Follow these rules when coding for LilyPond.
133 Hopefully, this can be replaced by general GNU guidelines in the
134 future. Even better would be to have an English (en_BR, en_AM)
135 helping programmers writing consistent messages for all GNU
138 Not-preferred messages are marked with `+'. By convention,
139 ungrammatical examples are marked with `*'.
144 Every message to the user should be localised (and thus be marked
145 for localisation). This includes warning and error messages.
148 Don't localise/gettextify:
152 `programming_error ()'s
155 `programming_warning ()'s
161 output strings (PostScript, TeX, etc.)
166 Messages to be localised must be encapsulated in `_ (STRING)' or
167 `_f (FORMAT, ...)'. Eg:
170 warning (_ ("need music in a score"));
171 error (_f ("cannot open file: `%s'", file_name));
174 In some rare cases you may need to call `gettext ()' by hand. This
175 happens when you pre-define (a list of) string constants for later
176 use. In that case, you'll probably also need to mark these string
177 constants for translation, using `_i (STRING)'. The `_i' macro is
178 a no-op, it only serves as a marker for `xgettext'.
181 char const* messages[] = {
182 _i ("enable debugging output"),
183 _i ("ignore lilypond version"),
191 puts (gettext (messages i));
195 See also `flower/getopt-long.cc' and `lily/main.cc'.
198 Do not use leading or trailing whitespace in messages. If you need
199 whitespace to be printed, prepend or append it to the translated
203 message (Calculating line breaks... + " ");
207 Error or warning messages displayed with a file name and line
208 number never start with a capital, eg,
211 foo.ly: 12: not a duration: 3
214 Messages containing a final verb, or a gerund (`-ing'-form) always
215 start with a capital. Other (simpler) messages start with a
221 Not declaring: `foo'.
225 Avoid abbreviations or short forms, use `cannot' and `do not'
226 rather than `can't' or `don't'
227 To avoid having a number of different messages for the same
228 situation, we'll use quoting like this `"message: `%s'"' for all
229 strings. Numbers are not quoted:
232 _f ("cannot open file: `%s'", name_str)
233 _f ("cannot find character number: %d", i)
237 Think about translation issues. In a lot of cases, it is better to
238 translate a whole message. The english grammar mustn't be imposed
239 on the translator. So, instead of
242 stem at + moment.str () + does not fit in beam
248 _f ("stem at %s does not fit in beam", moment.str ())
252 Split up multi-sentence messages, whenever possible. Instead of
255 warning (_f ("out of tune! Can't find: `%s'",
257 warning (_f ("cannot find font `%s', loading default",
264 warning (out of tune:;
265 warning (_f ("cannot find: `%s', "Key_engraver"));
266 warning (_f ("cannot find font: `%s', font_name));
267 warning (_f ("Loading default font"));
271 If you must have multiple-sentence messages, use full punctuation.
272 Use two spaces after end of sentence punctuation. No punctuation
273 (esp. period) is used at the end of simple messages.
276 _f ("Non-matching braces in text `%s', adding braces", text)
277 Debug output disabled. Compiled with NPRINT.
278 _f ("Huh? Not a Request: `%s'. Ignoring.", request)
282 Do not modularise too much; a lot of words cannot be translated
283 without context. It's probably safe to treat most occurences of
284 words like stem, beam, crescendo as separately translatable words.
287 When translating, it is preferable to put interesting information
288 at the end of the message, rather than embedded in the middle.
289 This especially applies to frequently used messages, even if this
290 would mean sacrificing a bit of eloquency. This holds for original
291 messages too, of course.
294 en: cannot open: `foo.ly'
295 + nl: kan `foo.ly' niet openen (1)
296 kan niet openen: `foo.ly'* (2)
297 niet te openen: `foo.ly'* (3)
301 The first nl message, although grammatically and stylistically
302 correct, is not friendly for parsing by humans (even if they speak
303 dutch). I guess we'd prefer something like (2) or (3).
306 Do not run make po/po-update with GNU gettext < 0.10.35