Changes between Version 20 and Version 21 of Submitting/C


Ignore:
Timestamp:
06/11/14 10:22:24 (11 years ago)
Author:
martinl
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Submitting/C

    v20 v21  
    1241249.  Use `fprintf()` instead of `printf()`
    125125   
    126     For errors and warnings please use the `G_fatal_error()` and
    127 `G_warning()` functions. General messages for the user should use
    128 `G_message()` while debug messages should use `G_debug()` whenever
    129 possible. There are two variants to `G_message()`: `G_verbose_message()`
    130 which will only display the message if in `--verbose` mode, and
    131 `G_important_message()` which will always show the message unless
    132 the module is running in `--quiet` mode. `G_fatal_error()` and
    133 `G_warning()` will always be displayed regardless of verbosity setting.
    134 Messages sent to any of these functions will be printed to stderr.
     126    For errors and warnings please use the `G_fatal_error()` and `G_warning()` functions. General messages for the user should use `G_message()` while debug messages should use `G_debug()` whenever
     127possible. There are two variants to `G_message()`: `G_verbose_message()` which will only display the message if in `--verbose` mode, and `G_important_message()` which will always show the message unless the module is running in `--quiet` mode. `G_fatal_error()` and `G_warning()` will always be displayed regardless of verbosity setting. Messages sent to any of these functions will be printed to stderr.
    135128
    136129    `G_message()` output is not expected to be sent to pipe or file.
    137130
    138     Always use the gettext macros with `_("")` for user messages,
    139 example:
     131    Always use the gettext macros with `_("")` for user messages, example:
    140132{{{
    141133      G_fatal_error(_("Vector map <%s> not found"), name);
    142134}}}
    143     It is suggested to add a comment line before translatable user message
    144 to give a hint to translators about meaning or use of
    145 cumbersome or obscure message. First word in the comment must be GTC
    146 - GRASS translation comment,
     135    It is suggested to add a comment line before translatable user message to give a hint to translators about meaning or use of cumbersome or obscure message. First word in the comment must be GTC - GRASS translation comment,
    147136 
    148137    Example:
     
    159148
    160149
    161     Pipe/file data output:
    162 For data output redirected to pipe or file, please use `fprintf()` and
    163 specify the stdout stream as follows:
     150    Pipe/file data output: For data output redirected to pipe or file, please use `fprintf()` and specify the stdout stream as follows:
    164151{{{
    165152      fprintf(stdout, ...);
     
    169156}}}
    170157
    171 10. Use the GRASS library function `G_asprintf()` instead of the
    172 standard C functions `asprintf()`, `vsnprintf()` and `snprintf()`. These
    173 functions are not portable or have other issues.  Example:
     15810. Use the GRASS library function `G_asprintf()` instead of the standard C functions `asprintf()`, `vsnprintf()` and `snprintf()`. These functions are not portable or have other issues.  Example:
    174159{{{
    175160    char *msg;
     
    182167
    183168
    184 11. Use the following GRASS library functions instead of the standard C
    185 functions. The reason for this is that the following functions ensure
    186 good programming practice (e.g. always checking if memory was allocated)
    187 and/or improves portability. PLEASE refer to the programmers manual
    188 for the proper use (e.g. determining if any casts are needed for arguments
    189 or return values) of these library functions. They may perform a task
    190 slightly different from their corresponding C library function, and thus,
    191 their use may not be the same.
     16911. Use the following GRASS library functions instead of the standard C functions. The reason for this is that the following functions ensure good programming practice (e.g. always checking if memory was allocated)
     170and/or improves portability. PLEASE refer to the programmers manual for the proper use (e.g. determining if any casts are needed for arguments or return values) of these library functions. They may perform a task slightly different from their corresponding C library function, and thus, their use may not be the same.
    192171{{{   
    193172        G_malloc() instead of malloc()
     
    200179        G_sleep() instead of sleep()
    201180}}}
    202         Could somebody please add others (please verify that they are
    203 useful and safe first)
     181        Could somebody please add others (please verify that they are useful and safe first)
    204182
    205183
    20618412. Use function names which fulfill the official GNU naming convention: http://www.gnu.org/prep/standards/html_node/Names.html#Names
    207185
    208     Instead of naming a function like: `MyNewFunction()` use underscores
    209 for seperation and lower case letters: `my_new_function()``.
     186    Instead of naming a function like: `MyNewFunction()` use underscores for seperation and lower case letters: `my_new_function()``.
    210187
    211188
     
    223200    This is safe comparing to nested `/* comments */`
    224201
    225     Functions in the library must be documented in doxygen style to
    226 get them into the programmer's manual (generate with `make pdfdocs` or `make htmldocs`).
    227 See [src:grass/trunk/lib/gis/] for examples.
    228 
    229 
    230 14. PLEASE take the time to add comments throughout your code explaining what
    231 the code is doing. It will save a HUGE amount of time and frustration for
    232 other programmers that may have to change your code in the future.
    233 
    234 
    235 15. To promote a consistent coding style, please use the "indent" program
    236 on all new C modules using the following switches:
     202    Functions in the library must be documented in doxygen style to get them into the programmer's manual (generate with `make pdfdocs` or `make htmldocs`). See [src:grass/trunk/lib/gis/] for examples.
     203
     204
     20514. PLEASE take the time to add comments throughout your code explaining what the code is doing. It will save a HUGE amount of time and frustration for other programmers that may have to change your code in the future.
     206
     207
     20815. To promote a consistent coding style, please use the "indent" program on all new C modules using the following switches:
    237209{{{
    238210     $ indent -bad -bap -bbb -br -bli0 -bls -cli0 -ncs -fc1 -hnl -i4 \
     
    240212      -npsl -nsc -nsob -saf -sai -saw -sbi0 -ss -ts8 -ut main.c
    241213}}}
    242     Existing code should not be re-indented except in extreme cases, as this
    243 will make "diff" comparisons with older versions impossible. If indent is
    244 needed, do not check in any changes other than the indentation in the same
    245 commit! Do add the indent switches and any indent warning messages to the
    246 SVN log. Any change or fix mixed in with an indent is very hard to track
    247 making it hard for others to follow the change or fix any new bugs.
    248 For your convenience use the src:grass/trunk/tools/grass_indent.sh script.
     214    Existing code should not be re-indented except in extreme cases, as this will make "diff" comparisons with older versions impossible. If indent is needed, do not check in any changes other than the indentation in the same commit! Do add the indent switches and any indent warning messages to the SVN log. Any change or fix mixed in with an indent is very hard to track
     215making it hard for others to follow the change or fix any new bugs. For your convenience use the src:grass/trunk/tools/grass_indent.sh script.
    249216
    250217
    25121816. Platform dependent code:
    252     Do not remove `#ifdef __CYGWIN__` and/or `#ifndef __CYGWIN__` lines and
    253 their encapsulated lines from source code (one example was that someone
    254 removed `drand48` definition.)
     219    Do not remove `#ifdef __CYGWIN__` and/or `#ifndef __CYGWIN__` lines and their encapsulated lines from source code (one example was that someone removed `drand48` definition.)
    255220
    256221
    25722217. Suggested compiler flags:
    258     We suggest to use very strict compiler flags to capture errors
    259 at the very beginning. Here our list of flags, please use them
    260 to configure you development version of GRASS:
     223    We suggest to use very strict compiler flags to capture errors at the very beginning. Here our list of flags, please use them to configure you development version of GRASS:
    261224
    262225    GNU/Linux:
     
    272235
    273236
    274 18. Make sure a new line is at the end of each file and UNIX style newlines
    275 are used (`\n`).
     23718. Make sure a new line is at the end of each file and UNIX style newlines are used (`\n`).
    276238
    277239
     
    301263
    302264
    303 21. Have a function included in your module which writes to the history
    304 file of the map (e.g. command line, parameters etc.). See e.g.
    305 [src:grass/raster/r.patch/main.c]
     26521. Have a function included in your module which writes to the history file of the map (e.g. command line, parameters etc.). See e.g. source:grass/raster/r.patch/main.c
    306266
    307267    (the same applies to vector and raster3d modules!)
    308268
    309269
    310 22. Standard parser options: use `G_define_standard_option()` whenever possible
    311 to define standard module command line options. This will save you time,
    312 create fewer bugs, and make things easier on the translators.
    313 See [src:grass/trunklib/gis/parser.c] for details of the function definition.
     27022. Standard parser options: use `G_define_standard_option()` whenever possible to define standard module command line options. This will save you time, create fewer bugs, and make things easier on the translators.
     271See source:grass/trunklib/gis/parser.c for details of the function definition.
    314272
    315273
     
    323281
    32428225. GRASS/Environment variables:
    325    If you add a new variable, please follow the naming convention.
    326 All variables are described in src:grass/trunk/lib/init/variables.html
    327 
    328 
    329 26. Be sure to develop on top of the LATEST GRASS code (which is in our SVN
    330 repository). You can re-check before submission with `svn diff`:
    331 
    332     Be sure to create unified (`diff -u`) format. "Plain" diffs (the default
    333 format) are risky, because they will apply without warning to code which
    334 has been substantially changed; they are also harder to read than unified.
    335 
    336     Such diffs should be made from the top-level directory, e.g.
    337 `svn diff display/d.vect/main.c`; that way, the diff will
    338 include the pathname rather than just an ambiguous `main.c`.
     283   If you add a new variable, please follow the naming convention. All variables are described in src:grass/trunk/lib/init/variables.html
     284
     285
     28626. Be sure to develop on top of the LATEST GRASS code (which is in our SVN repository). You can re-check before submission with `svn diff`:
     287
     288    Be sure to create unified (`diff -u`) format. "Plain" diffs (the default format) are risky, because they will apply without warning to code which has been substantially changed; they are also harder to read than unified.
     289
     290    Such diffs should be made from the top-level directory, e.g. `svn diff display/d.vect/main.c`; that way, the diff will include the pathname rather than just an ambiguous `main.c`.
    339291
    340292
     
    369321    You can easily write specific tests for your modules.
    370322
    371     If your module is part of GRASS and you created some standard test
    372 cases, please contact the developers to add your tests to the
    373 default test suite.  This will automatize complex test scenarios
    374 and assure to find bugs much faster, if changes were made to your
    375 modules or to the grass library.
    376 
    377     Consider to subscribe to the GRASS Quality Assessment System to
    378 get immediate notification about the code quality:
     323    If your module is part of GRASS and you created some standard test cases, please contact the developers to add your tests to the default test suite.  This will automatize complex test scenarios and assure to find bugs much faster, if changes were made to your modules or to the grass library.
     324
     325    Consider to subscribe to the GRASS Quality Assessment System to get immediate notification about the code quality:
    379326
    380327    http://lists.osgeo.org/mailman/listinfo/grass-qa
     
    435382    For your convenience use the src:grass/trunk/tools/module_svn_propset.sh script.
    436383
    437 30. Use doxygen style for source code documentation. It is required
    438 for GRASS libraries, but also recommended for GRASS modules.
    439 
    440     Do not use structural command inside documentation block since it
    441 leads to some duplication of information (e.g. do not use `\fn`
    442 command in comment blocks). The exception is `\file` command for
    443 documenting a file, in this case structural command is required.
     38430. Use doxygen style for source code documentation. It is required for GRASS libraries, but also recommended for GRASS modules.
     385
     386    Do not use structural command inside documentation block since it leads to some duplication of information (e.g. do not use `\fn` command in comment blocks). The exception is `\file` command for documenting a file, in this case structural command is required.
    444387
    445388    For files
     
    476419}}}
    477420
    478 31. If you need to add support for a different library in the 'configure' script,
    479 you should first seek consent in the grass-dev mailing list (see below), then
    480 you need to expand 'configure.in' and run subsequently `autoconf-2.13` (later
    481 versions will not work) to re-generate 'configure'.
     42131. If you need to add support for a different library in the 'configure' script, you should first seek consent in the grass-dev mailing list (see below), then you need to expand 'configure.in' and run subsequently `autoconf-2.13` (later versions will not work) to re-generate 'configure'.
    482422
    48342332. Tell the other developers about the new code using the following e-mail: