r23636: Adding coding style guide for Samba 3.0 branches (no differences from Tridge...
[kai/samba.git] / README.Coding
1 ##
2 ## Coding conventions in the Samba 3.0 tree
3 ##
4
5 ===========
6 Quick Start
7 ===========
8
9 Coding style guidelines are about reducing the number of unnecessary
10 reformatting patches and making things easier developers to work together.
11 You don't have to like them or even agree with them, but once put in place
12 we all have to abide by them (or vote to change them).  However, coding
13 style should never outweigh coding itself and so the the guidelines
14 described here are hopefully easier enough to follow as they are very
15 common and supported by tools and editors.
16
17 The basic style, also mentioned in the SAMBA_4_0/prog_guide.txt is the
18 Linux kernel coding style (See Documentation/CodingStyle in the kernel
19 source tree).  The closely matches what most Samba developers use already
20 anyways.
21
22 But to save you the trouble of reading the Linux kernel style guide, here
23 are the highlights.
24
25
26 * Maximum Line Width is 80 Characters
27   The reason is not for people with low-res screens but rather sticking
28   to 80 columns prevents you from easily nesting more than one level of
29   if statements or other code blocks.  Use source/script/count_80_col.pl
30   to check your changes.
31
32 * Use 8 Space Tabs to Indent
33   No whitespace filler.
34
35 * No Trailing Whitespace
36   Use source/script/strip_trail_ws.pl to clean you files before committing.
37
38 * Follow the K&R guidelines.  We won't go throw them all here.  You have
39   a copy of "The C Programming Language" anyways right?  You can also use
40   the format_indent.sh script found in source/script/ if all else fails.
41
42
43
44 ============
45 Editor Hints
46 ============
47
48 Emacs
49 -----
50 Add the follow to your $HOME/.emacs file:
51
52   (add-hook 'c-mode-hook
53         (lambda ()
54                 (c-set-style "linux")
55                 (c-toggle-auto-state)))
56
57
58 Vi
59 --
60 (Thanks to SATOH Fumiyasu <fumiyas@osstech.jp> for these hints):
61
62 For the basic vi eitor including with all variants of *nix, add the 
63 following to $HOME/.exrc:
64
65   set tabstop=8
66   set shiftwidth=8
67
68 For Vim, the following settings in $HOME/.vimrc will also deal with 
69 disaplaying trailing whitespace:
70
71   if has("syntax") && (&t_Co > 2 || has("gui_running"))
72         syntax on
73         function! ActivateInvisibleCharIndicator()
74                 syntax match TrailingSpace "[ \t]\+$" display containedin=ALL
75                 highlight TrailingSpace ctermbg=Red
76         endf
77         autocmd BufNewFile,BufRead * call ActivateInvisibleCharIndicator()
78   endif
79
80
81 ===================
82 Statement Reference
83 ===================
84
85 To be filled later in as needed.
86
87