source: branches/ithildin-1.1/doc/style.txt @ 578

Revision 578, 5.5 KB checked in by wd, 7 years ago (diff)

Expand tabs ('\t') to eight spaces.

  • Property svn:keywords set to Id Rev
Line 
1###############################################################################
2#
3# style.txt: guide to recommended programming style/practices
4#
5# Copyright 2002 the Ithildin Project.
6# See the COPYING file for more information on licensing and use.
7#
8# $Id$
9#
10###############################################################################
11
12The following is a guide to explain the programming style used in this
13software, and to advise future developers, creators or patches, or other
14maintainers in regards to desirable programming practices.
15
16All files should contain the above notice/comment group, from the file
17description to the copyright notice to the svn tag.  For C files this should be
18done using /* */ style comments, as demonstrated below.
19
20###############################################################################
21
22C source and header file practices:
23
24/*
25 * Very important comments look like this.  They should be full sentences,
26 * and be paragraphed as necessary.  Rambles, rants, and personal complaints
27 * do not provide any benefit to understanding code, please do not add them.
28 */
29
30/* Less important comments look like this, they may overflow (as demonstrated
31 * here), but should be properly spaced on the left and aligned. */
32
33/* All files have 4-space logical tab stops.  Two tab-stops should be replaced
34 * with a single <tab>, not eight spaces.  Text wraps at column 79 in all
35 * files.  Long lines should be extended using the \<newline> mechanism. */
36
37/* Each C file (including headers) should contain the above notice with the
38 * below format: (be sure to keep the svn tag!) */
39
40/*
41 * file.name: brief summary of the purpose of the file
42 *
43 * Copyright 2002 the Ithildin Project.
44 * See the COPYING file for more information on licensing and use.
45 *
46 * Further description as necessary for each file.  You may omit this if the
47 * purpose/function of the contents is particularly obvious, or is documented
48 * elsewhere.
49 */
50
51/* Header files should be wrapped for safety using the format:
52 * [MODULE_]HEADER_H
53 * however, the wrapping should go BELOW the copyright/description.  An example
54 * of the wrapping is below: */
55#ifndef IRCD_CLIENT_H
56#define IRCD_CLIENT_H
57/* code here */
58#endif
59 
60/* include statements should go as follows: any necessary system-wide files
61 * should be included first, followed by "stand.h", followed by any other
62 * necessary local includes.  The 'stand.h' include should be directly below
63 * the system includes (if they are used), and a blank line should be added
64 * before any necessary 'local' includes as demonstrated below: */
65
66#include <system/header.h>
67#include <ithildin/stand.h>
68
69/* be sure to include an id in your file so it can be identified later. */
70IDSTRING(rcsid, "$Id$");
71
72#include <module-header.h>
73
74/* function and structure declarations are placed below include (and other pre
75 * processor) directives.  Functions should be prototyped, and not
76 * safety-wrapped for K&R compilation (C89/90 has been out well over a decade).
77 * Function prototypes should not contain the names of the variables, only
78 * their types.  Variables should never be declared in header files, except as
79 * 'extern' and further declared in an appropriate C source file.  Structures
80 * should not, in most cases, be typedef'd.  examples follow: */
81
82/* Comments about the use of 'foo', and it's general purpose, go here.
83 * additionally, types should be separated from variable names by up to two
84 * tabstops.  Comments about structure's member variables' functions should be
85 * aligned whenever possible. */
86struct foo {
87    int            bar;        /* brief description of variable */
88    struct  baz abaz;        /* a baz structure */
89    longtypename avar;        /* another variable.
90
91    LIST_ENTRY(foo) lp; /* a list entry.  lists should be rolled with the
92                           macros in queue.h unless there is a pressing reason
93                           not to do so. */
94};
95
96/* Function prototypes go below structures.  Each function should be briefly
97 * described in the header file in which it is prototyped, and more fully
98 * described in its source file.  No attempt should be made to align the
99 * arguments of the function, and there should be a single space between the
100 * function's type(s) and the name of the function.  There should be no space
101 * between the name of the function and its argument list.  Functions with no
102 * arguments are prototyped as void, not with an empty list.  examples: */
103void func1(int, char *, char *, float);
104const int *func2(char *, char *);
105char *func3(void);
106
107/* Function definitions should resemble their prototyped definitions, except
108 * with named arguments.  Functions are defined in ANSI C format, NOT K&R
109 * format.  Each major function should be documented before declaration in a
110 * comment.  All variables within each function should be declared at the top
111 * of the function, unless it is necessary for clarity to declare them within a
112 * lower block.  There should be a blank line between the variable declarations
113 * and the beginning of function code, or a blank line between the function
114 * definition and the beginning of code if no variables are decalred.  Blank
115 * lines and comments should be used liberally to make the operations of a
116 * function clear.  examples are liberal in the code itself. */
117
118/* Braces go on the same line as the keyword/function, not on a separte line.
119 * They are optional for one-line if/else/for/while statements. */
120
121/* If other questions remain, and the style is not evident from existing code,
122 * please see the style(9) manual page on your nearest FreeBSD system *.
123
Note: See TracBrowser for help on using the repository browser.