IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2004, 11:57:43 AM (22 years ago)
Author:
eugene
Message:

changes to coding requirements from MHPCC comments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/misc/codeConventions.tex

    r505 r514  
    1 %%% $Id: codeConventions.tex,v 1.14 2004-04-22 22:33:38 price Exp $
     1%%% $Id: codeConventions.tex,v 1.15 2004-04-23 21:57:43 eugene Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    171171e.g. for file \file{psThing.h}:
    172172\begin{verbatim}
    173 /*
     173/** \file psThing.h
    174174 * Support for psThings
    175175 */
     
    186186} psThing;
    187187
     188/// make a new psThing
    188189psThing *psThingAlloc(int nthing);
     190
     191/// free an existing psThing
    189192void psThingFree(psThing *thing);
    190193
     
    486489
    487490All globally-visible symbols must be declared in a suitable header
    488 (.h) file.  Global private symbols (i.e.  those named \code{p_ps})
    489 should not appear in public header files, but rather in files whose
    490 names begin \code{p_ps}.
     491(.h) file.  Global private symbols should not appear in public header
     492files, but rather in separate, private header files.
    491493
    492494\subsection{Number Per Line}
     
    576578\item
    577579Function declarations should be preceeded by a short comment
    578 describing what the function does.
    579 
    580 \tbd{Discuss Doxygen}
     580describing what the function does.  These comment blocks should
     581include doxygen-style comments to provide a brief desription as well
     582as other warnings, bugs, etc as needed.
    581583
    582584\item The function's type should appear on the same line as the
     
    871873rigid adherence to the guideline.
    872874 
     875{ \small
    873876\begin{tabular}{lp{3in}p{3in}}
    874877\textbf{Identifier Type} &
     
    898901
    899902The names of all externally visible functions (i.e. all those that are
    900 not declared \code{static}) should be verbal phrases, in mixed
    901 case. The first two characters should be \code{ps}, with the first
    902 letter of each internal word capitalized.
    903 
    904 Functions that are visible at global scope but are not considered part
    905 of the public interface should be prefixed \code{p_ps}.
    906 
    907 Functions that are local to a file should \textit{not} start
    908 \code{ps} (or \code{p_ps}).
    909  
     903not declared \code{static}) should be verbal phrases, in mixed case.
     904
     905Namespaces should be protected by using special naming prefixes to
     906restrict the name space in particular libraries.  For example, the
     907PSLib functions are all prefixed with \code{ps}.
     908
    910909&
    911910
     
    927926standard. Non-globally visible words should start with a lowercase
    928927first letter; Internal words start with capital letters.
    929 
    930 Variables visible at global scope should begin with \code{ps},
    931 or \code{p_ps} if not considered part of the public interface.
    932 Variables that are local to a file should \textit{not} start
    933 with \code{ps} (or \code{p_ps}). These variables should be Capitalised
    934 at the beginning of each word.
    935928
    936929Variable names should be short yet meaningful. The choice of a
     
    943936
    944937&
    945 \code{int i; char c; float myWidth;}\hfil\break
     938\code{int i;}\hfil\break
     939\code{char c;}\hfil\break
     940\code{float myWidth;}\hfil\break
    946941\hfil\break
    947942\code{int psNumOTA;}\hfil\break
     
    959954enumerated types.
    960955
    961 The names of all enumerated types and C-preprocessor symbols (but not
    962 variables declared \code{const}) declared should start with
    963 \code{PS_} or \code{P_PS_} and the rest of the name should
    964 be uppercase with words separated by underscores (\code{_}). In the case of
    965 system utilities implemented as macros, the names may conform to the
    966 usual \PS{} conventions (e.g. \code{psAlloc}).
    967 
    968956&
    969957\code{#define PS_MAXLEN 40}\hfil\break
     
    971959
    972960\end{tabular}
     961}
    973962
    974963%------------------------------------------------------------------------------
     
    978967\subsection{When to Make Symbols Global}
    979968
    980 Declare all functions and variables \code{static} within a
    981 file if at all possible (n.b. do not confuse this use of \code{static}
    982 with its usage to make auto-variables within a function persistent).
     969Declare all functions and top-level variables \code{static} within a
     970file if they are not needed outside of the file.  {\bf Note:} do not
     971confuse this use of \code{static} with its usage to make
     972auto-variables within a function persistent.
    983973
    984974\subsection{Constants}
     
    987977small integers such as -1, 0, and 1 which are permitted to e.g. appear
    988978in a \code{for} loop as counter values. 
     979
     980\subsection{Type Qualifiers (const and restrict)}
     981
     982All interfaces and type definitions should use \code{const} and
     983\code{restrict} wherever appropriate. For example,
     984\begin{verbatim}
     985typedef struct {
     986    int n;
     987    float *restrict vec;
     988} psVec;
     989
     990psVec *psVecAdd(const restrict* psVec s1, const restrict* psVec s2);
     991\end{verbatim}
     992
     993\textit{{\bf Note:} compilers are free to ignore the \code{restrict}
     994keyword, so all code should be written to explicitly handle aliasing}.
     995
     996\subsection{structs and typedefs}
     997
     998All structs should be defined as \code{typedef}s.
     999
     1000A struct should not include a struct
     1001tag unless it's self-referential; E.g.
     1002\begin{verbatim}
     1003typedef struct myStruct {               // Omit "myStruct"
     1004    int x;
     1005} myStruct;
     1006
     1007typedef struct yourStruct {             // OK
     1008    struct yourStruct *next;
     1009    int x;
     1010} yourStruct;
     1011\end{verbatim}
    9891012
    9901013\subsection{Variable Assignments}
     
    11011124
    11021125\subsubsection{Special Comments}
     1126
     1127Doxygen has special comments which are used to provide specific notes
     1128in the code.  These are added in as special entries and sections in
     1129the Doxygen-generated documentation.  These special comments should be
     1130used in addition to the Doxygen usage to make these types of
     1131conditions easily searchable.
     1132
    11031133\begin{itemize}
    11041134\item
    1105 Use \code{XXX} in a comment to flag something that is bogus but works.
     1135Use \code{\warning} in a comment to flag something that is bogus but works.
    11061136
    11071137\item
    1108 Use \code{FIXME} to flag something that is bogus and broken.
    1109 
    1110 \tbd{Check Doxygen versions of these special comments. I could not
    1111 find any occurrence of \code{@notused@} in the Doxygen documentation}
    1112 \item
    1113 Use \code{NOTREACHED} to indicate a line of code that cannot be reached,
     1138Use \code{\bug} to flag something that is bogus and broken.
     1139
     1140\item
     1141Use \code{\todo} to note additional work to be done
     1142
     1143\item
     1144Use \code{\note} to make other general notes
     1145
     1146\item
     1147Use \code{\test} to list test cases
     1148
     1149\item
     1150Use \code{\notreached} to indicate a line of code that cannot be reached,
    11141151e.g.
    11151152\begin{verbatim}
     
    11211158
    11221159\item
    1123 Use \code{NOTUSED} to indicate unused arguments to a function:
     1160Use \code{\notused} to indicate unused arguments to a function:
    11241161e.g.
    11251162\begin{verbatim}
     
    11331170\end{verbatim}
    11341171\end{itemize}
    1135 
    1136 \subsubsection{\label{LAllocFree}10.4.6     Constructors/Destructors}
    1137 
    1138 Type definitions should always be accompanied by prototypes for
    1139 their constructors and destructors:
    1140 
    1141 \begin{itemize}
    1142 \item  The constructor should consist of the type name followed by
    1143 \code{Alloc}; e.g. a type \code{psImage} would
    1144 be created by a function
    1145 \begin{verbatim}
    1146 psImage *psImageAlloc(int nrow, int ncol);
    1147 \end{verbatim}
    1148 
    1149 \item  Similarly, the type should be freed with a destructor named
    1150 \code{typeFree}, e.g.
    1151 \begin{verbatim}
    1152 void psImageFree(psImage *img);
    1153 \end{verbatim}
    1154 
    1155 \item  The constructor should never return \code{NULL}, and
    1156 no code calling the constructor should ever check the return value.
    1157 
    1158 \item  The destructor must not return a value.
    1159 
    1160 \item  The destructor should handle being passed \code{NULL}
    1161 by simply returning immediately. This should not be treated as
    1162 an error condition.
    1163 
    1164 \item  The destructor should call \code{psMemGetRefCounter}; if the value is greater
    1165   than one, the destructor should simply call \code{psMemDecrRefCounter} and return.
    1166 
    1167 \end{itemize}
    1168 
    1169 \subsection{\label{LConvOps}Naming Conversion Operators}
    1170 
    1171 When defining a function to convert from one type to another, the
    1172 name should be of the form \code{psOldToAlloc}, e.g.\hfil\break
    1173 \code{psEquatorialToEcliptic} (\emph{not} \code{psEquatorial2Ecliptic}).
    1174 
    1175 \subsection{Order of I/O Arguments}
    1176 
    1177 Functions that assign to a variable should list that argument
    1178 \textit{first} (i.e. following the pattern of \code{strcpy}); e.g.
    1179 \begin{verbatim}
    1180 void psAddToVector(restrict psVec *outVec, const restrict psVec *inVec,
    1181                    int val);
    1182 \end{verbatim}
    1183 
    1184 \subsection{Type Qualifiers (const and restrict)}
    1185 
    1186 All interfaces and type definitions should use \code{const} and
    1187 \code{restrict} wherever appropriate. For example,
    1188 \begin{verbatim}
    1189 typedef struct {
    1190     int n;
    1191     float *restrict vec;
    1192 } psVec;
    1193 
    1194 psVec *psVecAdd(const restrict* psVec s1, const restrict* psVec s2);
    1195 \end{verbatim}
    1196 
    1197 \textit{{\bf Note:} compilers are free to ignore the \code{restrict}
    1198 keyword, so all code should be written to explicitly handle aliasing}.
    1199 
    1200 \subsection{structs and typedefs}
    1201 
    1202 All structs should be defined as \code{typedef}s.
    1203 
    1204 A struct should not include a struct
    1205 tag unless it's self-referential; E.g.
    1206 \begin{verbatim}
    1207 typedef struct myStruct {               // Omit "myStruct"
    1208     int x;
    1209 } myStruct;
    1210 
    1211 typedef struct yourStruct {             // OK
    1212     struct yourStruct *next;
    1213     int x;
    1214 } yourStruct;
    1215 \end{verbatim}
    12161172
    12171173%------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.