IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 22, 2004, 6:24:52 PM (22 years ago)
Author:
jhoblitt
Message:

misc changes and corrections
add Chop vs. Chomp section

File:
1 edited

Legend:

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

    r2401 r2403  
    1 %%% $Id: perlCodeConventions.tex,v 1.26 2004-11-23 02:53:47 jhoblitt Exp $
     1%%% $Id: perlCodeConventions.tex,v 1.27 2004-11-23 04:24:52 jhoblitt Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    7777common with Perl programmers.  Instead, it is an attempt to make the C and Perl
    7878coding styles as consistent as is reasonably feasible within the Pan-STARRS
    79 project.  This document also only contains brief discussion of Perl's
     79project.  This document only contains brief discussion of Perl's
    8080Object-Oriented features and none of it's more advanced features.
    8181
    8282\subsection{Applicability}
    8383
    84 This document is intended to be relevant with Perl 5.8.0 or later.
     84This document is intended to be relevant to Perl 5.8.0 or later.
    8585
    8686\subsection{To whom should I Complain?}
     
    148148\begin{itemize}
    149149\item
    150 A Bourne shell "she-bang" for perl.  \code{#!/usr/bin/perl}.
     150A Bourne shell ``she-bang'' for perl.  \code{#!/usr/bin/perl}.
    151151
    152152\item
     
    155155
    156156\item
    157 A minimum perl version requirement in long form (vStrings are not allowed).
    158 Where \code(requirement = revision + version / 1000 + subversion /
     157An optional minimum perl version requirement in long form (vStrings are not
     158allowed).  Where \code(requirement = revision + version / 1000 + subversion /
    1591591\_000\_000).  E.g. A minimum requirement of Perl 5.8.5 would be expressed as
    160160\code{use 5.008005}
     
    164164
    165165\item
    166 Any base classes.
     166Any modules to include.
    167167
    168168\item
     
    202202
    203203\item
    204 A minimum perl version requirement in long form (vStrings are not allowed).
     204An optional minimum perl version requirement in long form (vStrings are not allowed).
    205205Where \code(requirement = revision + version / 1000 + subversion / 1\_000\_000).
    206206E.g. A minimum requirement of Perl 5.8.5 would be expressed as \code{use
     
    210210A \code{use strict} and \code{use warnings} declaration.
    211211
     212\item
     213A module \code{VERSION} declaration.
     214
     215\item
     216Any ``base'' classes.
     217
    212218\item
    213219Any modules to include.
     
    237243
    238244\subsubsection{Plain Old Documentation}
     245\label{pod}
    239246
    240247This is the format for documentation in a \code{.pl} file after the
    241 \code{__END__} token and the \code{.pod} file that should accompany a
    242 a module (\code{.pm}).
     248\code{__END__} token and the \code{.pod} file that should accompany a module
     249(\code{.pm}).
    243250
    244251e.g. for file Foo.pod:
     
    432439\end{verbatim}
    433440
    434 \subsection{Documentation Comments}
     441\subsection{API Comments}
    435442\label{DocComments}
    436443
    437444Plain Old Documentation format or Pod will be used to produce documentation of
    438 the subroutines and variables in the exposed API.  Pod sections will appear
    439 above the section of code that they describe.
    440 
    441 An example of a Pod section defining the API of a subroutine.
    442 
    443 \begin{verbatim}
    444     =item * reallyCoolSubroutine
    445 
    446     Accepts a real number and a string.  Does some really cool stuff with it and
    447     returns a really cool thing.
    448 
    449     =cut
    450 
    451     sub reallyCoolSubroutine
    452     {
    453         my ($aNumber, $aString) = @_;
    454 
    455         # Do really cool stuff
    456 
    457         return $aThing;
    458     }
    459 \end{verbatim}
     445the subroutines and variables in the exposed API.  See Plain Old Documentation
     446(\S\ref{pod}).
    460447
    461448If you need to give information about a interface, or variable that isn't
    462449appropriate for Podification, use a normal implementation single-line or
    463 multi-line comment  immediately \textit{before} the code (as exampled above).
     450multi-line comment immediately \textit{before} the code (as exampled above).
    464451
    465452
     
    511498\subsection{Initialization}
    512499
    513 Try to initialize local variables where they're declared.  Do not initialize
    514 variables with an empty string or list - this is pointless.
    515 
    516 reason not to initialize a variable where it's declared is if the
    517 initial value depends on some computation occurring first.
     500Try to initialize local variables where they're declared.
     501
     502Do not initialize variables with an empty string or list - this is pointless.
     503
     504A reason not to initialize a variable where it's declared is if the initial
     505value depends on some computation occurring first.
    518506
    519507In some cases it may be necessary to initialize a variable to suppress
     
    534522\begin{itemize}
    535523\item
    536 Subroutine declarations should be preceded by a short comment describing what
    537 the subroutine does.  These documentation comments should include a brief
    538 description as well as other warnings, bugs, etc. as needed.
     524Subroutine declarations may be preceded by a short comment describing what the
     525subroutine does.  These comments should include a brief description as well as
     526other warnings, bugs, etc. as needed.
    539527
    540528\item
     
    547535
    548536\item
    549 Closing brace \CODE.}. starts a line by itself, except when it is a null
    550 statement the \CODE.}. should appear immediately after the \CODE.{..
     537Closing brace \CODE.}. starts a line by itself.  Null statement should have the
     538closing brace immediately after the opening brace.  e.g. \CODE.{}.
    551539
    552540\item
     
    684672\subsection{Perl style for, foreach Statements}
    685673
    686 A Perlish \code{for} or \code{foreach} statement (also known as an iterator)
    687 should have the following form:
     674A Perlish \code{for} or \code{foreach} statement should have the following
     675form:
    688676
    689677\begin{verbatim}
     
    10421030
    10431031If an expression containing a binary operator appears before the \code{?} in
    1044 the ternary \code{?: }operator, it should be parenthesized. Example:
     1032the ternary \code{?:} operator, it should be parenthesized. Example:
    10451033
    10461034\begin{verbatim}
     
    10621050
    10631051Don't use ``bare-words'' as filehandles except for \code{STDIN}, \code{STDOUT},
    1064 or \code{STDERR}.
     1052and \code{STDERR}.
    10651053
    10661054\begin{verbatim}
     
    10801068\end{verbatim}
    10811069
     1070\subsubsection{Chop vs. Chomp}
     1071
     1072Don't use \code{chop} to remove newline characters as it will remove any
     1073character (newline or not).
     1074
     1075\begin{verbatim}
     1076    my $foo = "baz\n";                  # string with newline
     1077   
     1078    chomp($foo);                        # removes "\n" - Correct
     1079    chomp($foo);                        # chomping the same string twice is safe
     1080
     1081    chop($foo);                         # removes "z" - AVOID!
     1082\end{verbatim}
     1083
    10821084%------------------------------------------------------------------------------
    10831085\appendix                               %Begin Appendices
Note: See TracChangeset for help on using the changeset viewer.