Use gnulib pipe module instead of popen(3).
[m4.git] / doc / STYLE
blob3cc59b32c21ee6c733c01e99064ae9dfd554178e
1 GNU m4 STYLE - The way this code should look.           -*- outline -*-
3 Before all else this code follows the GNU coding standards and
4 indentation style described in standards.info.  Additionally the
5 following restrictions on coding style apply:
7 * C STANDARD
9   + All of this code is ANSI-C, GNU C extensions are conditional so that
10     the code will compile cleanly on non GLIBC/GCC systems.
12 * SYMBOL NAMES
14   + All non-static symbols have a prefix either `M4' or `m4'.
16   + All exported symbols which are part of the library api have the
17     prefix `m4_'.
19   + Symbols which are exported from the library (for efficiency perhaps)
20     but are not part of the supported library api have the prefix
21     `m4__',
23   + Function names should be verb phrases; m4_module_get_field.
25   + Functions which exist to be used as callbacks from API functions, and
26     hence which likely have strange looking parameters are named with the
27     suffix `_CB', to make it obvious why they look a little odd.
29   + Macros which implement fast versions of functions share the
30     same name as the function they replace, and may not evaluate
31     parameters more than once.
33   + Otherwise macros are in uppercase, prefixed `M4' if they are visible
34     to the user after installation, to help the user know when to be
35     careful about multiple evaluations of parameters.
37   + Function names should contain the name of the module they belong to,
38     usually immediately after the namespace prefix: m4_module_load.
40   + Variables should not be exported (not true, but I'm working on it),
41     but accessor functions used instead.  Note the `get'/`set' part of
42     the symbol name comes before the module part: m4_get_module_macros.
44   + Structures come with accessor macros named <struct name>_<field
45     name> (in upper case), to make refactoring of nested structures much
46     easier: SYMBOL_FLAGS.
48   + Structures are typedeffed separately, and the structure itself
49     generally not exported unless in the `m4__' namespace to support
50     fast accessor macros.
52   + An opaque abstract data type (ADT) can have public and private fields:
53     By convention public fields will have exported accessor functions (and
54     maybe also fast macro versions of the same), and private fields will
55     not export accessors at all.  However, there should be non-exported
56     (or at least in the `m4__' namespace) accessor functions for even the
57     private fields of an ADT to aid possible later refactoring.
59 * ARCHITECTURE
61   + There are four groups of sources in subdirectories: `gnu' contains
62     the files maintained outside of m4, as a portability layer when building
63     the souce for non-glibc2 machines; `m4' contains the functionality for
64     libm4 and enables the user to write modules; `modules' implements the
65     builtin macros for the m4 binary; `src' is a small wrapper program
66     which links libm4 and loads initial modules to implement the m4 engine.
68   + The headers in gnu need to be managed carefully: gnulib headers
69     can be included by other files in the same directory using `#include
70     "file.h"', and from files in other directories with `#include
71     <m4/file.h>'.  The include path to invocations of the compiler from
72     various Makefile.am are set to prevent the possibility of picking up
73     an m4/file.h when the system file.h (e.g stdbool.h) is present.  This,
74     in turn means the replacement headers can live in gnulib/m4 without
75     suffering a renaming scheme at configure time.  Don't break with the
76     `#include' convention, or the compile will go wrong in hard to debug
77     ways on some platforms.
79   + Low coupling.  Classes (and in C, by this I mean files of functions)
80     should not rely on a web of other classes to be useful, they should
81     communicate with as few other classes as possible.
83   + High cohesion.  The api and caller boundaries should be well defined
84     and adhered to; a class should do one thing only.
86 ========================================================================
88 Copyright (C) 2003, 2006 Free Software Foundation, Inc.
90 Permission is granted to copy, distribute and/or modify this document
91 under the terms of the GNU Free Documentation License, Version 1.2 or
92 any later version published by the Free Software Foundation; with no
93 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
94 Texts.  A copy of the license is included in the ``GNU Free
95 Documentation License'' file as part of this distribution.