IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2334


Ignore:
Timestamp:
Nov 10, 2004, 4:27:56 PM (22 years ago)
Author:
jhoblitt
Message:

converted the statements section
spelling fixes

File:
1 edited

Legend:

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

    r2333 r2334  
    1 %%% $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $
     1%%% $Id: perlCodeConventions.tex,v 1.4 2004-11-11 02:27:56 jhoblitt Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    127127A Bourne shell "she-bang" for perl.  \code{#!/usr/bin/perl}.
    128128\item
    129 A Copright notice followed by a blank commented line.  Then one commented line
     129A Copyright notice followed by a blank commented line.  Then one commented line
    130130per CVS keyword to be expanded.
    131131\item
    132 A minimum perl version requiremt in long form (vStrings are not allowed).
    133 Where \code(requriemnt = revision + version / 1000 + subversion / 1\_000\_000).
     132A minimum perl version requirement in long form (vStrings are not allowed).
     133Where \code(requirement = revision + version / 1000 + subversion / 1\_000\_000).
    134134E.g. A minimum requirement of Perl 5.8.5 would be expressed as \code{use
    1351355.008005}
     
    155155# Copyright (C) 2004  Joshua Hoblitt
    156156#
    157 # $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $
     157# $Id: perlCodeConventions.tex,v 1.4 2004-11-11 02:27:56 jhoblitt Exp $
    158158
    159159use 5.008005;   # optional
     
    181181\begin{itemize}
    182182\item
    183 A Copright notice followed by a blank commented line.  Then one commented line
     183A Copyright notice followed by a blank commented line.  Then one commented line
    184184per CVS keyword to be expanded.
    185185\item
    186186A Perl Package declaration.  \code{package Foo}
    187187\item
    188 A minimum perl version requiremt in long form (vStrings are not allowed).
    189 Where \code(requriemnt = revision + version / 1000 + subversion / 1\_000\_000).
     188A minimum perl version requirement in long form (vStrings are not allowed).
     189Where \code(requirement = revision + version / 1000 + subversion / 1\_000\_000).
    190190E.g. A minimum requirement of Perl 5.8.5 would be expressed as \code{use
    1911915.008005}
     
    212212# Copyright (C) 2004  Joshua Hoblitt
    213213#
    214 # $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $
     214# $Id: perlCodeConventions.tex,v 1.4 2004-11-11 02:27:56 jhoblitt Exp $
    215215
    216216package Foo;
     
    355355should not be included as a comment.
    356356
    357 Discussion of nontrivial or nonobvious design decisions is
     357Discussion of nontrivial or non-obvious design decisions is
    358358appropriate, but avoid duplicating information that is present in (and
    359359clear from) the code. It is too easy for redundant comments to get out
     
    389389\subsubsection{Multi-Line Comments}
    390390
    391 Merely a repitition of single-line comments.
     391Merely a repetition of single-line comments.
    392392
    393393\subsubsection{Trailing Comments}
     
    464464
    465465In almost all situations with the exception of when parameters are being passed
    466 into a subrutine.
     466into a subroutine.
    467467
    468468Do not put different types on the same line. Example:
     
    487487\end{verbatim}
    488488
    489 Note: This restiction does not apply to Perl's built in variables.
     489Note: This restriction does not apply to Perl's built in variables.
    490490
    491491\subsection{Initialization}
     
    502502Variables should ordinarily be declared at the top of the block in
    503503which they appear, unless there is some reason to declare them later.
    504 This allows them to be initialised as they are created, and naturally
     504This allows them to be initialized as they are created, and naturally
    505505associates their declaration with their use.
    506 
    507 
    508 Indexes of loops should usually be declared on the line above loop statement.
    509 
    510 \begin{verbatim}
    511 my $i = 0;
    512 for (i < $maxLoops) {
    513     # do stuff
    514 
    515     $i++;
    516 }
    517 \end{verbatim}
    518506
    519507\subsection{Subroutine Declarations}
     
    524512\begin{itemize}
    525513\item
    526 Subroutine declarations should be preceeded by a short comment describing what
     514Subroutine declarations should be preceded by a short comment describing what
    527515the subroutine does.  These documentation comments should include a brief
    528 desription as well as other warnings, bugs, etc. as needed.
     516description as well as other warnings, bugs, etc. as needed.
    529517
    530518\item
     
    542530
    543531\item
    544 The last line before the closing brace must explicity declare a return value.
     532The last line before the closing brace must explicitly declare a return value.
    545533\end{itemize}
    546534
     
    562550Each line should usually contain only one statement. Example:
    563551\begin{verbatim}
    564 x = sqrt(x2);                           // Correct
    565 i++;                                    // Correct 
    566 x = sqrt(x2); i++;                      // Avoid!
     552$x = sqrt($x2);                         # Correct
     553$i++;                                   # Correct 
     554$x = sqrt($x2); $i++;                   # Avoid!
    567555\end{verbatim}
    568556
    569557An example of a reasonably two-statement line is:
    570558\begin{verbatim}
    571 argv++; argc--;
     559$foo++; $bar--;
    572560\end{verbatim}
    573561where the two actions are intimately related.
     
    575563\subsection{Compound Statements}
    576564
    577 Compound statements are statements that contain lists of statements
    578 enclosed in braces. See the
    579 following sections for examples.
     565Compound statements are statements that contain lists of statements enclosed in
     566braces. See the following sections for examples.
    580567
    581568\begin{itemize}
     
    594581\subsection{return Statements}
    595582
    596 A \code{return} statement with a value should not use parentheses unless they make the return value more obvious in some way. Example:
    597 \begin{verbatim}
    598 return;
    599 
    600 return myDisk.size;
    601 
    602 return (size ? size : defaultSize);
    603 
    604 \end{verbatim}
    605 
    606 \subsection{if, if-else, if else-if else Statements}
     583A \code{return} statement with a value should not use parentheses unless they
     584make the return value more obvious in some way.  All subroutines must have an
     585explicit, non-null, return statement.   Example:
     586
     587\begin{verbatim}
     588return undef;                           # Correct
     589return;                                 # Wrong!
     590
     591return $myDisk->size;
     592
     593return ($size ? $size : $defaultSize);
     594\end{verbatim}
     595
     596Note:  In absence of an explicit return statement Perl will return the results
     597of the last statement executed.  A null return statement \code{return;} also
     598causes the result of the last statement executed to be returned.
     599
     600\subsection{if, if-else, if elsif else Statements}
     601
     602\code{if} statements must always use braces {} around statements and parenthesis
     603() around conditionals.
    607604
    608605The \code{if-else} class of statements should have the following form:
     
    620617if (condition) {
    621618    statements;
    622 } else if (condition) {
     619} elsif (condition) {
    623620    statements;
    624621} else {
    625622    statements;
    626623}
    627 
    628 \end{verbatim}
    629 
    630 Note: \code{if} statements always use braces {}. Avoid the following
    631 error-prone form:
    632 \begin{verbatim}
    633 if (condition)                          // AVOID! THIS OMITS THE BRACES {}!
    634     statement;
    635 \end{verbatim}
    636 
    637 \subsection{for Statements}
     624\end{verbatim}
     625
     626\subsection{C style for Statements}
    638627
    639628A \code{for} statement should have the following form:
     629
    640630\begin{verbatim}
    641631for (initialization; condition; update) {
     
    644634\end{verbatim}
    645635
    646 An empty \code{for} statement (one in which all the work is done
    647 in the initialization, condition, and update clauses) should have one of
    648 the following forms:
    649 \begin{verbatim}
    650 for (initialization; condition; update);
     636For example:
     637
     638\begin{verbatim}
     639for (my $i =0; $i < 100; $i++) {
     640    print "$i\n";
     641}
     642\end{verbatim}
     643
     644An empty \code{for} statement (one in which all the work is done in the
     645initialization, condition, and update clauses) should have the following forms:
     646
     647\begin{verbatim}
    651648for (initialization; condition; update) {}
    652649\end{verbatim}
     
    666663}
    667664\end{verbatim}
    668 An empty \code{while} statement should have one of the following forms:
    669 \begin{verbatim}
    670 while (condition);
     665An empty \code{while} statement should have the following form:
     666\begin{verbatim}
    671667while (condition) {}
    672668\end{verbatim}
     
    680676} while (condition);
    681677\end{verbatim}
    682 
    683 \subsection{switch Statements}
    684 
    685 A \code{switch} statement should have the following form):
    686 \begin{verbatim}
    687 switch (condition) {
    688     case ABC:
    689         statements;
    690         /* falls through */
    691 
    692     case DEF:
    693     case GHI:
    694         statements;
    695         break;
    696 
    697     case XYZ:
    698         statements;
    699         break;
    700 
    701     default:
    702         statements;
    703         break;
    704 }
    705 \end{verbatim}
    706 
    707 Every time a case falls through (doesn't include a \code{break}
    708 statement), add a comment where the \code{break} statement would
    709 normally be. This is shown in the preceding code example with the
    710 \code{/* falls through */} comment. A comment is not required (or
    711 expected) when the fall-through is between multiple case statements.
    712 
    713 Every \code{switch} statement should include a default case, which
    714 should come last. The \code{break} in the default case is redundant,
    715 but it prevents a fall-through error if later another \code{case} is
    716 later (and illegally) added after the default clause.
    717 
    718 When switching on an enumerated type, if all the elements of the type
    719 are included in the switch a default clause should still be added (not
    720 all compilers diagnose missing elements).  In this case, the action in
    721 the default clause should be to generate an error and abort.
    722678
    723679\subsection{label Statements}
     
    871827\code{float myWidth;}\hfil\break
    872828\hfil\break
    873 \code{int psNumOTA;}\hfil\break
     829\code{int pseudo;}\hfil\break
    874830\code{int p_psMyFiddleFactor;}\hfil\break
    875831
Note: See TracChangeset for help on using the changeset viewer.