Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/README.Coding

    r414 r740  
    99
    1010Coding style guidelines are about reducing the number of unnecessary
    11 reformatting patches and making things easier for developers to work together.
     11reformatting patches and making things easier for developers to work
     12together.
    1213You don't have to like them or even agree with them, but once put in place
    1314we all have to abide by them (or vote to change them).  However, coding
     
    1617common and supported by tools and editors.
    1718
    18 The basic style, also mentioned in prog_guide4.txt, is the Linux kernel coding
    19 style (See Documentation/CodingStyle in the kernel source tree). This closely
    20 matches what most Samba developers use already anyways.
     19The basic style, also mentioned in prog_guide4.txt, is the Linux kernel
     20coding style (See Documentation/CodingStyle in the kernel source tree). This
     21closely matches what most Samba developers use already anyways, with a few
     22exceptions as mentioned below.
    2123
    2224But to save you the trouble of reading the Linux kernel style guide, here
     
    2426
    2527* Maximum Line Width is 80 Characters
    26   The reason is not for people with low-res screens but rather sticking
     28  The reason is not about people with low-res screens but rather sticking
    2729  to 80 columns prevents you from easily nesting more than one level of
    2830  if statements or other code blocks.  Use source3/script/count_80_col.pl
     
    3032
    3133* Use 8 Space Tabs to Indent
    32   No whitespace filler.
     34  No whitespace fillers.
    3335
    3436* No Trailing Whitespace
    35   Use source3/script/strip_trail_ws.pl to clean you files before committing.
    36 
    37 * Follow the K&R guidelines.  We won't go throw them all here.  You have
    38   a copy of "The C Programming Language" anyways right?  You can also use
     37  Use source3/script/strip_trail_ws.pl to clean up your files before
     38  committing.
     39
     40* Follow the K&R guidelines.  We won't go through all of them here. Do you
     41  have a copy of "The C Programming Language" anyways right? You can also use
    3942  the format_indent.sh script found in source3/script/ if all else fails.
    4043
     
    6568  set shiftwidth=8
    6669
    67 For Vim, the following settings in $HOME/.vimrc will also deal with 
    68 displaying trailing whitespace::
     70For Vim, the following settings in $HOME/.vimrc will also deal with
     71displaying trailing whitespace:
    6972
    7073  if has("syntax") && (&t_Co > 2 || has("gui_running"))
     
    9194--------
    9295
    93 Comments should always use the standard C syntax.  C++ 
     96Comments should always use the standard C syntax.  C++
    9497style comments are not currently allowed.
    9598
     99The lines before a comment should be empty. If the comment directly
     100belongs to the following code, there should be no empty line
     101after the comment, except if the comment contains a summary
     102of multiple following code blocks.
     103
     104This is good:
     105
     106        ...
     107        int i;
     108
     109        /*
     110         * This is a multi line comment,
     111         * which explains the logical steps we have to do:
     112         *
     113         * 1. We need to set i=5, because...
     114         * 2. We need to call complex_fn1
     115         */
     116
     117        /* This is a one line comment about i = 5. */
     118        i = 5;
     119
     120        /*
     121         * This is a multi line comment,
     122         * explaining the call to complex_fn1()
     123         */
     124        ret = complex_fn1();
     125        if (ret != 0) {
     126        ...
     127
     128        /**
     129         * @brief This is a doxygen comment.
     130         *
     131         * This is a more detailed explanation of
     132         * this simple function.
     133         *
     134         * @param[in]   param1     The parameter value of the function.
     135         *
     136         * @param[out]  result1    The result value of the function.
     137         *
     138         * @return              0 on success and -1 on error.
     139         */
     140        int example(int param1, int *result1);
     141
     142This is bad:
     143
     144        ...
     145        int i;
     146        /*
     147         * This is a multi line comment,
     148         * which explains the logical steps we have to do:
     149         *
     150         * 1. We need to set i=5, because...
     151         * 2. We need to call complex_fn1
     152         */
     153        /* This is a one line comment about i = 5. */
     154        i = 5;
     155        /*
     156         * This is a multi line comment,
     157         * explaining the call to complex_fn1()
     158         */
     159        ret = complex_fn1();
     160        if (ret != 0) {
     161        ...
     162
     163        /*This is a one line comment.*/
     164
     165        /* This is a multi line comment,
     166           with some more words...*/
     167
     168        /*
     169         * This is a multi line comment,
     170         * with some more words...*/
    96171
    97172Indention & Whitespace & 80 columns
    98173-----------------------------------
    99174
    100 To avoid confusion, indentations are to be 8 character with tab (not
    101 8 ' ' characters.  When wrapping parameters for function calls,
     175To avoid confusion, indentations have to be tabs with length 8 (not 8
     176' ' characters).  When wrapping parameters for function calls,
    102177align the parameter list with the first parameter on the previous line.
    103 Use tabs to get as close as possible and then fill in the final 7 
     178Use tabs to get as close as possible and then fill in the final 7
    104179characters or less with whitespace.  For example,
    105180
     
    107182                   arg3);
    108183
    109 The previous example is intended to illustrate alignment of function 
    110 parameters across lines and not as encourage for gratuitous line 
     184The previous example is intended to illustrate alignment of function
     185parameters across lines and not as encourage for gratuitous line
    111186splitting.  Never split a line before columns 70 - 79 unless you
    112187have a really good reason.  Be smart about formatting.
     
    126201        if ( x == 1 )
    127202
    128 Yes we have a lot of code that uses the second form and we are trying 
     203Yes we have a lot of code that uses the second form and we are trying
    129204to clean it up without being overly intrusive.
    130205
    131206Note that this is a rule about parentheses following keywords and not
    132 functions.  Don't insert a space between the name and left parentheses when 
     207functions.  Don't insert a space between the name and left parentheses when
    133208invoking functions.
    134209
    135210Braces for code blocks used by for, if, switch, while, do..while, etc.
    136 should begin on the same line as the statement keyword and end on a line
    137 of their own.  NOTE: Functions are different and the beginning left brace
    138 should begin on a line of its own.
     211should begin on the same line as the statement keyword and end on a line
     212of their own. You should always include braces, even if the block only
     213contains one statement.  NOTE: Functions are different and the beginning left
     214brace should be located in the first column on the next line.
    139215
    140216If the beginning statement has to be broken across lines due to length,
    141217the beginning brace should be on a line of its own.
    142218
    143 The exception to the ending rule is when the closing brace is followed by 
    144 another language keyword such as else or the closing while in a do..while 
     219The exception to the ending rule is when the closing brace is followed by
     220another language keyword such as else or the closing while in a do..while
    145221loop.
    146222
    147 Good examples::
     223Good examples:
    148224
    149225        if (x == 1) {
    150226                printf("good\n");
    151227        }
     228
     229        for (x=1; x<10; x++) {
     230                print("%d\n", x);
     231        }
     232
     233        for (really_really_really_really_long_var_name=0;
     234             really_really_really_really_long_var_name<10;
     235             really_really_really_really_long_var_name++)
     236        {
     237                print("%d\n", really_really_really_really_long_var_name);
     238        }
     239
     240        do {
     241                printf("also good\n");
     242        } while (1);
     243
     244Bad examples:
     245
     246        while (1)
     247        {
     248                print("I'm in a loop!\n"); }
    152249
    153250        for (x=1;
     
    155252             x++)
    156253        {
    157                 print("%d\n", x);
    158         }
    159 
    160         do {
    161                 printf("also good\n");
    162         } while (1);
    163 
    164 Bad examples::
    165 
    166         while (1)
    167         {
    168                 print("I'm in a loop!\n"); }
    169        
     254                print("no good\n");
     255        }
     256
     257        if (i < 10)
     258                print("I should be in braces.\n");
     259
    170260
    171261Goto
    172262----
    173263
    174 While many people have been academically taught that goto's are fundamentally
    175 evil, they can greatly enhance readability and reduce memory leaks when used
    176 as the single exit point from a function.  But in no Samba world what so ever
    177 is a goto outside of a function or block of code a good idea.
    178 
    179 Good Examples::
     264While many people have been academically taught that "goto"s are
     265fundamentally evil, they can greatly enhance readability and reduce memory
     266leaks when used as the single exit point from a function. But in no Samba
     267world what so ever is a goto outside of a function or block of code a good
     268idea.
     269
     270Good Examples:
    180271
    181272        int function foo(int y)
     
    184275                int ret = 0;
    185276
    186                 if ( y < 10 ) {
     277                if (y < 10) {
    187278                        z = malloc(sizeof(int)*y);
    188279                        if (!z) {
     
    194285                print("Allocated %d elements.\n", y);
    195286
    196          done: 
    197                 if (z)
     287         done:
     288                if (z) {
    198289                        free(z);
     290                }
    199291
    200292                return ret;
     
    205297-----------------------
    206298
    207 When invoking functions that return pointer values, either of the following 
    208 are acceptable.  Use you best judgement and choose the more readable option.
    209 Remember that many other people will review it.::
     299When invoking functions that return pointer values, either of the following
     300are acceptable. Use your best judgement and choose the more readable option.
     301Remember that many other persons will review it:
    210302
    211303        if ((x = malloc(sizeof(short)*10)) == NULL ) {
     
    213305        }
    214306
    215 or::
     307or:
    216308
    217309        x = malloc(sizeof(short)*10);
     
    224316--------------------
    225317
    226 Samba has large amounts of historical code which makes use of data types 
    227 commonly supported by the C99 standard. However, at the time such types 
    228 as boolean and exact width integers did not exist and Samba developers 
    229 were forced to provide their own.  Now that these types are guaranteed to 
    230 be available either as part of the compiler C99 support or from lib/replace/,
    231 new code should adhere to the following conventions:
     318Samba has large amounts of historical code which makes use of data types
     319commonly supported by the C99 standard. However, at the time such types
     320as boolean and exact width integers did not exist and Samba developers
     321were forced to provide their own.  Now that these types are guaranteed to
     322be available either as part of the compiler C99 support or from
     323lib/replace/, new code should adhere to the following conventions:
    232324
    233325  * Booleans are of type "bool" (not BOOL)
    234326  * Boolean values are "true" and "false" (not True or False)
    235327  * Exact width integers are of type [u]int[8|16|32|64]_t
     328
     329
     330Typedefs
     331--------
     332
     333Samba tries to avoid "typedef struct { .. } x_t;" so we do always try to use
     334"struct x { .. };". We know there are still such typedefs in the code,
     335but for new code, please don't do that anymore.
     336
     337Make use of helper variables
     338----------------------------
     339
     340Please try to avoid passing function calls as function parameters
     341in new code. This makes the code much easier to read and
     342it's also easier to use the "step" command within gdb.
     343
     344Good Example:
     345
     346        char *name;
     347
     348        name = get_some_name();
     349        if (name == NULL) {
     350                ...
     351        }
     352
     353        ret = some_function_my_name(name);
     354        ...
     355
     356
     357Bad Example:
     358
     359        ret = some_function_my_name(get_some_name());
     360        ...
     361
Note: See TracChangeset for help on using the changeset viewer.