home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / gfx / 3d / irit / docs / coding.std next >
Encoding:
Text File  |  1995-02-09  |  7.7 KB  |  285 lines

  1. These are the coding standards I am using. If you make some changes to the
  2. code, please attempt to follow these rules.
  3.  
  4. Gershon Elber
  5.  
  6. gershon@cs.technion.ac.il
  7.  
  8. ------------------------------------------------------------------------------
  9.  
  10.  
  11. GENERAL
  12. -------
  13.  
  14. Code should not exceed column 80. If the code is going to "look"
  15. better with more that 80 columns it is allowed but should be
  16. restricted as possible.
  17.  
  18. NESTING
  19. -------
  20.  
  21. Nesting of all expressions is by 4 spaces. Tabs used are 8 spaces.
  22.  
  23. SPACES
  24. ------
  25.  
  26. No spaces are allowed after '(' and before ')' in a function call or
  27. math expression. However, spaces are allowed between arguments after
  28. the comma or between operations:
  29.  
  30.     sin(x);
  31.     Function1(x, y, z);
  32.     x + 5 * sin(y);
  33.  
  34. FUNCTION HEADER'S COMMENT
  35. -------------------------
  36.  
  37. Function comments will have the following form:
  38.  
  39. /*****************************************************************************
  40. * DESCRIPTION:                                     M
  41. * Multi line description of the function. This is a text that will be copied M
  42. * to the programmer's manual iff the end of the line is M instead of a *     M
  43. * like this line.                                 M
  44. *   If a V is found at the end of the line, it is copied Verbatim. Example:  M
  45. * A x + B y + C z + D w + E = 0 defines an hyper plane in four space.        V
  46. *                                         M
  47. *   Proper indentation will be given to algorithms or sequences that begin   M
  48. * with an alpha-numeric values followed by a point. For example:             M
  49. *                                         M
  50. * 1. One letter    which sets the option letter (i.e. 'x' for option '-x').     M
  51. *    1.1 Allow even sub sequences.                         M
  52. * 2. '!' or '%'    to determines if this option is    really optional    ('%') or     M
  53. *    it    must be provided by the user ('!').                     M
  54. * 3. '-' always.                                 M
  55. * 4. Sequences that start with either '!' or '%'.                 M
  56. *       Each sequence will be followed by one or two characters    which        M
  57. *    defines the kind of the input:                            M
  58. *    4.1 d, x, o, u - integer is expected (decimal, hex, octal base or         M
  59. *          unsigned).                             M
  60. *    4.2 D, X, O, U - long integer is expected (same as above).             M
  61. *    4.3 f - float number is expected.                         M
  62. *                                         *
  63. * PARAMETERS:                                     M
  64. *   I1: one per line, must have an M at the end to show up in prog manual.   M
  65. *   C2: this parameter is the second one.                     M
  66. *                                         *
  67. * RETURN VALUE:                                     M
  68. *   int: Number of manuals to create.                         M
  69. *                                         *
  70. * KEYWORDS:    (only if a global non static function).                 M
  71. *    ProgrammerManual, manual, documentation                     M
  72. *****************************************************************************/
  73. int ProgrammerManual(int I1, char C2)
  74. {
  75. }
  76.  
  77. Functions that are obviously auxiliary can have the postfix Aux, must be
  78. static, and can have documentation as:
  79.  
  80. /*****************************************************************************
  81. * DESCRIPTION:                                                               *
  82. * Auxiliary function to function SymbPiecewiseRuledSrfApprox             *
  83. *****************************************************************************/
  84. static CagdSrfStruct *CagdPiecewiseRuledSrfAux(CagdSrfStruct *Srf,
  85.                            CagdBType ConsistentDir,
  86.                            CagdRType Epsilon,
  87.                            CagdSrfDirType Dir)
  88.  
  89. The function comment must be followed very precisely so they could be
  90. grabbed out of the code directly into the programmer's manual. If you
  91. are using the emacs editor (If you dont, you better switch to it), add
  92. irit.el from the irit subdirectory to your .emacs. This emacs-lisp file
  93. contains a definition for make-irit-c-function which expands a skeleton
  94. from a given prototype. Once irit.el is installed, type
  95. 'M-x make-irit-c-function' followed by a function prototype 'int Test(char c)'.
  96.  
  97. Static functions will never have 'M' or 'V' as last character in line. Only
  98. '*'.
  99.  
  100. INTERNAL COMMENTS
  101. -----------------
  102.  
  103. Internal comments will be aligned to the right to column 80 if the
  104. are commenting expression in the same line:
  105.  
  106.     i %= 2;                              /* Is i even? */
  107.  
  108. Comments that explains the following block, will be left aligned as
  109. the block. The comment does not need to be right aligned to column 80
  110. as well:
  111.  
  112.     /* This is a comment for the next line. */
  113.     i %= 2;
  114.  
  115.  
  116. FUNCTION AND VARIABLE NAMES
  117. ---------------------------
  118.  
  119. Both function and variable names will have NO UNDERSCORES. Words will be
  120. capitalized to distinguish them from each other. Variables of single
  121. character will be lower case. Examples of valid names:
  122.  
  123.     ThisIsAFunction, VariableOne, X1, i, j
  124.  
  125. VARIABLE'S DECLARATIONS
  126. -----------------------
  127. Variables will be declared at the deepest nesting possible. That is, if
  128. a variable is used in one module, it will be static to the module. If the
  129. variable is used in one function, it will be defined in one function. If
  130. a variable is used in one block in one function, it will be defined in that
  131. block. Variables will be declared static first, followed by automatic.
  132. Variables will be declared from simple type to complex/composed ones.
  133. Variables that are intialized are to be declared one per line, indented
  134. once from the indentation level of the variable type. Example:
  135.  
  136.     static int
  137.     LastCount = 0;
  138.     static RealType
  139.     LastValue = 0.0;
  140.     static IPObjectStruct *TmpObj;
  141.     char Str[LINE_LEN], *p,
  142.     *Name = "MyName";
  143.     int Dir = REAL_PTR_TO_INT(RDir),
  144.     OldOrder = Dir == CAGD_CONST_U_DIR ? Srf -> VOrder : Srf -> UOrder,
  145.     NewOrder = REAL_PTR_TO_INT(RNewOrder);
  146.     IPObjectStruct *SrfObj;
  147.     CagdSrfStruct *TSrf,
  148.     *Srf = PObjSrf -> U.Srfs;
  149.  
  150.  
  151. PARAMETERS OF FUNCTIONS
  152. -----------------------
  153.  
  154. Parameters of function prototypes will either be all in one line:
  155.  
  156.     int Func1Test(int Len, RealType *Vect)
  157.  
  158. or all arguments must be aligned one below the other:
  159.  
  160.     static CagdSrfStruct *CagdPiecewiseRuledSrfAux(CagdSrfStruct *Srf,
  161.                                CagdBType ConsistentDir,
  162.                                CagdRType Epsilon,
  163.                                CagdSrfDirType Dir)
  164.  
  165. Local (to a file) functions must be declared static and a prototype of the
  166. function should also be placed in the beginning of the file. Otherwise,
  167. for a non static function, a prototype must be place in the appropriate
  168. header ('.h' file) file.
  169.  
  170.  
  171. BLOCKS
  172. ------
  173.  
  174. Blocks starts with '{' and ends with '}'. If the block is beginning of
  175. function then it will start with '{' at column 1 and end at column 1
  176. with '}'. Otherwise, it will start with some expression as for/if/while
  177. etc. in the nesting form: 
  178.  
  179.     expression {
  180.     .
  181.     .
  182.     .
  183.     }
  184.  
  185. FOR
  186. ---
  187.     for (x = 0; x < 10; x++)
  188.  
  189.     or
  190.  
  191.     for (x = 0, i = 1;
  192.          x < 5;
  193.          x++, i--)
  194.  
  195.     The body of the for loop can never be in the same line where the ')'
  196.     is. The ')' will be followed by '{' and the body will start in the next
  197.     line nested 4 space deapper:
  198.  
  199.     for (....)
  200.         x = sin(j);
  201.     or
  202.     for (....) {
  203.         x = y / j;
  204.         y = j + 2;
  205.     }
  206.  
  207. WHILE
  208. -----
  209.     while (x > 0)
  210.         x--;                       /* Better use x = 0! */
  211.  
  212. or
  213.  
  214.     while (x > 0 && y > 0) {
  215.         x -= 4;
  216.         y -= 4;
  217.     }
  218.  
  219. or
  220.  
  221.     while (x > 0 &&
  222.            x < 5)
  223.         x /= 2;
  224.  
  225.  
  226. IF
  227. --
  228.  
  229.     if (x > 0)
  230.         x = -x;
  231.  
  232. or
  233.  
  234.     if (x > 0 && y > 0) {
  235.         x = -x;
  236.         y = -y;
  237.     }
  238.  
  239. or
  240.  
  241.     if (x > 0)
  242.         x = -x;
  243.     else
  244.         x /= 2;
  245.  
  246. or
  247.  
  248.     if (x > 0)
  249.         x = -x;
  250.     else if (x < -100)
  251.         x /= 20;
  252.     else
  253.         x /= 2;
  254.  
  255. If an if expression has an else clause both bodies will be aligned 4
  256. space deep (The body of the if clause can not be in same line as the
  257. if and must be aligned with the else body).
  258.  
  259.  
  260. SWITCH
  261. ------
  262.  
  263.     switch (i) {
  264.         case 1:
  265.         printf("1");
  266.         break;
  267.         case 2:
  268.         printf("2");
  269.         break;
  270.         case 3:
  271.         printf("3");
  272.         break;
  273.         default:
  274.         printf("Too big");
  275.         break;
  276.     }
  277.  
  278.  
  279. FINAL REMARK
  280. ------------
  281.  
  282. If you are still not sure how the code should be formated in some specific
  283. case, consult the code. Out of over 100k of lines of code, you are most
  284. likely to find a similar case to yours.
  285.