IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2591


Ignore:
Timestamp:
Dec 1, 2004, 12:34:23 PM (22 years ago)
Author:
jhoblitt
Message:

only use source code I hold the copyright on for examples
LaTeX formatting
document formatting
grammar and spelling fixes
misc example corrections
misc corrections
moved example source code to appendix
added several new programming practices

Location:
trunk/doc/misc
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/misc/.perltidyrc

    r2475 r2591  
    1 # $Id: .perltidyrc,v 1.5 2004-11-25 02:27:57 jhoblitt Exp $
     1# $Id: .perltidyrc,v 1.6 2004-12-01 22:34:22 jhoblitt Exp $
    22
    33# check the syntax with perl
     
    1414-i=4
    1515
    16 # continued statements get no extra indenting
     16# continued statements get indented 4 spaces
    1717-ci=4
    1818
  • trunk/doc/misc/Foo.pm

    r2402 r2591  
    1 # Copyright (C) 2004  Joshua Hoblitt
     1# Copyright (C) 2004  Author's Name
    22#
    33# $Id$
     
    1818use constant MAXFOO => 3;               # maximum number of foos
    1919
    20 my $baz;                                # is a lexical variable in the top level scope
     20our $bar;                               # is a package variable
     21
     22my $baz;                                # is a package scoped lexical variable
    2123
    2224sub fuu
     
    2830
    2931__END__
    30 
    31 ...
  • trunk/doc/misc/Foo.pod

    r2480 r2591  
    1313=head1 DESCRIPTION
    1414
    15 More details about what this modules does with Baz.
    16 
    1715=head1 USAGE
    1816
     
    2422=head2 Methods
    2523
     24=head3 Constructors
     25
     26=over 4
     27
     28=item * new
     29
     30=back
     31
     32=head3 Object Methods
     33
     34=over 4
     35
     36=item * foo
     37
     38=back
     39
    2640=head3 Class Methods
    2741
    2842=over 4
    2943
    30 =item * methodOne
    31 
    32 details of methodOne
    33 
    34 =item * methodTwo
    35 
    36 details of methodTwo
    37 
    38 ...
     44=item * bar
    3945
    4046=back
     47
     48=head3 Destructors
     49
     50=over 4
     51
     52=item * DESTROY
     53
     54=back
     55
     56=head1 DEVELOPER NOTES
     57
     58=head2 REFERENCES
    4159
    4260=head1 CREDITS
  • trunk/doc/misc/buildIndex.pl

    r2471 r2591  
    55# $Id: buildIndex.pl,v 1.1 2004/04/20 22:16:17 jhoblitt Exp $
    66
     7use 5.008;
     8
    79use strict;
    810use warnings;
    911
    10 use vars qw( $VERSION );
    11 $VERSION = '0.01';
     12our $VERSION = '0.01';
    1213
    1314use File::Basename qw();
     
    2122use Pod::Usage qw( pod2usage );
    2223
    23 my ($verbose, $help, $path, $index_dir);
     24my ($verbose, $help, $path, $indexDir);
    2425GetOptions(
    2526    'verbose' => \$verbose,
    2627    'path=s'  => \$path,
    27     'index=s' => \$index_dir,
     28    'index=s' => \$indexDir,
    2829    )
    2930    or pod2usage(2);
     
    3233pod2usage(-msg => "Required option: --path|-p", -exitval => 2) unless $path;
    3334
    34 $index_dir = $path . "/.index" unless defined $index_dir;
     35$indexDir = $path . "/.index" unless defined $indexDir;
    3536
    3637##my $stripper = HTML::Strip->new;
    3738
    3839my $writer = Plucene::Index::Writer->new(
    39     $index_dir,
     40    $indexDir,
    4041    Plucene::Plugin::Analyzer::PorterAnalyzer->new(),
    4142    1    # Create the index from scratch
     
    4445my $doc = Plucene::Document->new;
    4546
    46 foreach my $file_name (File::Find::Rule->file->name(qr/^msg\d+\.html/)->in($path)) {
    47     print "indexing: $file_name\n" if $verbose;
    48     $writer->add_document(parse_mhonarc_html($file_name));
     47foreach my $filename (File::Find::Rule->file->name(qr/^msg\d+\.html/)->in($path)) {
     48    print "indexing: $filename\n" if $verbose;
     49    $writer->add_document(parseMhonarcHtml($filename));
    4950}
    5051
    51 sub parse_mhonarc_html
     52sub parseMhonarcHtml
    5253{
    53     my $file_name = shift;
    54 
    55     my $tree = HTML::TreeBuilder->new_from_file($file_name);
     54    my $filename = shift;
     55
     56    my $tree = HTML::TreeBuilder->new_from_file($filename);
    5657    my $doc  = Plucene::Document->new;
    5758
    58     $doc->add(Plucene::Document::Field->Keyword(file_name => File::Basename::basename($file_name),));
     59    $doc->add(Plucene::Document::Field->Keyword(file_name => File::Basename::basename($filename),));
    5960
    6061    # get the header values for to, cc, from, date, and subject
    6162
    6263    # find the <div> tag labeled header
    63     my $header_tag = $tree->look_down(_tag => "div", id => "header");
     64    my $headerTag = $tree->look_down(_tag => "div", id => "header");
    6465
    6566    my %headers;
    6667
    67     foreach my $row_node ($header_tag->look_down(_tag => "tr")) {
     68    foreach my $rowNode ($headerTag->look_down(_tag => "tr")) {
    6869
    6970        # process each row of the header
    7071
    7172        # get name of header field
    72         my $name_node = $row_node->look_down(_tag => "td");
    73         my $name = lc($name_node->look_down(_tag => "em")->as_text);
    74         $name_node->delete;
     73        my $nameNode = $rowNode->look_down(_tag => "td");
     74        my $name = lc($nameNode->look_down(_tag => "em")->as_text);
     75        $nameNode->delete;
    7576
    7677        # get content of header field
    77         my $content_node = $row_node->look_down(_tag => "td");
    78         my $content      = $content_node->as_text;
     78        my $contentNode = $rowNode->look_down(_tag => "td");
     79        my $content     = $contentNode->as_text;
    7980
    8081        # index "cc" as part of "to"
     
    9091
    9192    # find the <div> tag labeled content
    92     my $content_tag = $tree->root->look_down(_tag => "div", id => "content");
     93    my $contentTag = $tree->root->look_down(_tag => "div", id => "content");
    9394
    9495    # index message body
    9596    print "\tadding to index content\n" if $verbose;
    96     $doc->add(Plucene::Document::Field->UnStored(content => $content_tag->as_text));
     97    $doc->add(Plucene::Document::Field->UnStored(content => $contentTag->as_text));
    9798
    9899    return $doc;
     
    105106=head1 NAME
    106107
    107 build_index.pl - generate Plucene/Lucene index of MHonarc archives
     108buildIndex.pl - generate Plucene/Lucene index of MHonarc archives
    108109
    109110=head1 SYNOPSIS
    110111
    111     build_index.pl --path dir [--index dir] [--verbose]
     112    buildIndex.pl --path dir [--index dir] [--verbose]
    112113
    113114    or
    114115
    115     build_index.pl -p dir [-i dir] [-v]
     116    buildIndex.pl -p dir [-i dir] [-v]
    116117
    117118    or
    118119
    119     build_index.pl [--help | -h | -? | --version]
     120    buildIndex.pl [--help | -h | -? | --version]
    120121
    121122=head1 DESCRIPTION
     
    148149=back
    149150
    150 =head1 DEVELOPERS
     151=head1 DEVELOPER NOTES
    151152
    152153The parser extracts the C<to>, C<cc>, C<from>, C<subject>, and C<date> headers
     
    201202Place - Suite 330, Boston, MA  02111-1307, USA.
    202203
    203 The full text of the license can be found in the LICENSE file included with
    204 this module, or in the L<perlgpl> Pod as supplied with Perl 5.8.1 and later.
     204The full text of the license can be found in the L<perlgpl> Pod as supplied
     205with Perl 5.8.1 and later.
    205206
    206207=head1 SEE ALSO
  • trunk/doc/misc/foo.pl

    r2409 r2591  
    11#!/usr/bin/perl
    22
    3 # Copyright (C) 2004  Joshua Hoblitt
     3# Copyright (C) 2004  Author's Name
    44#
    55# $Id$
     
    2525__END__
    2626
    27 ...
     27=pod
     28
     29=head1 NAME
     30
     31foo.pl - Does something with Baz.
     32
     33=head1 SYNOPSIS
     34
     35    foo.pl --baz
     36
     37    ...
     38
     39=head1 DESCRIPTION
     40
     41=head1 OPTIONS
     42
     43=over 4
     44
     45=item * --baz
     46
     47=back
     48
     49=head1 DEVELOPER NOTES
     50
     51=head1 REFERENCES
     52
     53=head1 CREDITS
     54
     55Just me, myself, and I.
     56
     57=head1 SUPPORT
     58
     59Please contact the author directly via e-mail.
     60
     61=head1 AUTHOR
     62
     63Principle authors and contact info.
     64
     65=head1 COPYRIGHT
     66
     67Copyright (C) 2004  Author's Name.  All rights reserved.
     68
     69This program is free software; you can redistribute it and/or modify it under
     70the terms of the GNU General Public License as published by the Free Software
     71Foundation; either version 2 of the License, or (at your option) any later
     72version.
     73
     74This program is distributed in the hope that it will be useful, but WITHOUT ANY
     75WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
     76PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     77
     78You should have received a copy of the GNU General Public License along with
     79this program; if not, write to the Free Software Foundation, Inc., 59 Temple
     80Place - Suite 330, Boston, MA  02111-1307, USA.
     81
     82The full text of the license can be found in the L<perlgpl> Pod as supplied
     83with Perl 5.8.1 and later.
     84
     85=head1 SEE ALSO
     86
     87L<Bar::Baz>
     88
     89=cut
  • trunk/doc/misc/perlCodeConventions.tex

    r2541 r2591  
    1 %%% $Id: perlCodeConventions.tex,v 1.41 2004-11-30 22:42:30 jhoblitt Exp $
     1%%% $Id: perlCodeConventions.tex,v 1.42 2004-12-01 22:34:22 jhoblitt Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    2525DR00& 2004-11-12 & First Draft\\
    2626\hline
    27 DR01& 2004-11-24 & Second Draft\\
     27DR01& 2004-12-01 & Second Draft\\
    2828\RevisionsEnd
    2929
     
    4646\pagenumbering{arabic}
    4747
     48
     49%------------------------------------------------------------------------------
     50
    4851\section{Introduction}
    49 
    5052\subsection{Ancestry}
    5153
     
    6062    CODE CONVENTIONS FOR THE JAVA^TM PROGRAMMING LANGUAGE.
    6163    Copyright 1995-1999 Sun
    62     Microsysytems, Inc.  All rights reserved.
     64    Microsystems, Inc.  All rights reserved.
    6365\end{verbatim}
    6466
     
    8789\subsection{Conformance}
    8890
    89 If any of the conventions estiblished in this document conflict with source
     91If any of the conventions established in this document conflict with source
    9092code that has been formated by \code{perltidy} (see \S\ref{perltidy}), the
    9193formatting as output by \code{perltidy} will be considered to be in compliance
     
    98100
    99101\code{<rhl@astro.princeton.edu>}.
     102
    100103
    101104%------------------------------------------------------------------------------
     
    126129\hline
    127130\file{Makefile.PL}&
    128   The preferred name for the file that calls \code{ExtUtils::MakeMaker} or
    129 \code{Module::Build} to create the makefile for Swig generated C code.\\
     131The preferred name for the file that invokes a ``build'' process.  Typically
     132this calls \code{ExtUtils::MakeMaker} or \code{Module::Build} setup the the
     133necessary files to install a module or compile Swig generated C code.\\
    130134\end{tabular}
    131135\end{center}
     
    136140\section{File Organization}
    137141
     142General rules:
     143
     144\begin{itemize}
     145\item
    138146A file consists of sections that should be separated by blank lines
    139147and an optional comment identifying each section.
    140148
     149\item
    141150Files longer than 1000 lines are cumbersome and should be avoided.
    142151
     152\item
    143153For an example of a properly formatted program, see
    144 Source File Example (\S\ref{SourceExample}).
    145 
     154Complete Program Example (\S\ref{SourceExample}).
     155
     156\item
    146157``Scripts'' have user documentation included at the end of the file.
    147158
     159\item
    148160``Modules'' have documentation included in a companion \code{.pod}.
     161\end{itemize}
    149162
    150163\subsection{Source Files}
    151 
    152164\subsubsection{Perl Scripts}
    153165
     
    156168\begin{itemize}
    157169\item
    158 A Bourne shell ``she-bang'' for perl.  \code{#!/usr/bin/perl}.
     170A Bourne shell ``she-bang'' for \code{perl}.  \code{#!/usr/bin/perl}.
    159171
    160172\item
     
    163175
    164176\item
    165 An optional minimum perl version requirement in long form (vStrings are not
    166 allowed).  Where \code(requirement = revision + version / 1000 + subversion /
    167 1\_000\_000).  E.g. A minimum requirement of Perl 5.8.5 would be expressed as
    168 \code{use 5.008005}
     177An optional minimum \code{perl} version requirement in long form (vStrings are
     178not allowed).  Where \code(requirement = revision + version / 1000 + subversion
     179/ 1\_000\_000).  e.g. A minimum requirement of \code{perl} 5.8.5 would be
     180expressed as \code{use 5.008005}
    169181
    170182\item
     
    182194
    183195\item
    184 Any script level "globals" declared as lexical variables.  E.g. \code{my $foo}
     196Any script level "globals" declared as lexical variables.  e.g. \code{my $foo}
    185197
    186198\item
     
    188200
    189201\item
    190 A \code{__END__} token to instruct the perl parser to stop looking for
     202A \code{__END__} token to instruct the \code{perl} parser to stop looking for
    191203executable code.
    192204
     
    195207\end{itemize}
    196208
    197 e.g. for file \file{foo.pl}:
    198 
    199 \verbatiminput{foo.pl}
     209For an example of a properly organized script, see Script File Example
     210(\S\ref{foo.pl}).
    200211
    201212\subsubsection{Perl Modules}
    202213
    203 Perl Module/Namespaces deviate slightly from the standard naming conventions in
    204 that the first character is always capitalized.  All Pan-STARRS specific
    205 modules should be under the top level \code{PS::} namespace.
     214Module files should have the following order:
    206215
    207216\begin{itemize}
     
    214223
    215224\item
    216 An optional minimum perl version requirement in long form (vStrings are not allowed).
    217 Where \code(requirement = revision + version / 1000 + subversion / 1\_000\_000).
    218 E.g. A minimum requirement of Perl 5.8.5 would be expressed as \code{use
    219 5.008005}
     225An optional minimum \code{perl} version requirement in long form (vStrings are
     226not allowed).  Where \code(requirement = revision + version / 1000 + subversion
     227/ 1\_000\_000).  e.g. A minimum requirement of \code{perl} 5.8.5 would be
     228expressed as \code{use 5.008005}
    220229
    221230\item
     
    235244
    236245\item
    237 Any script level ``globals'' declared as lexical variables.  E.g. \code{my
    238 $foo}
     246Any package variables.  e.g. \code{our $foo}
     247
     248\item
     249Any package scoped lexical variables.  e.g. \code{my $foo}
    239250
    240251\item
     
    248259A \code{__END__} token to instruct the perl parser to stop looking for
    249260executable code.
     261
    250262\end{itemize}
    251263
    252 e.g. for file \file{Foo.pm}:
    253 
    254 \verbatiminput{Foo.pm}
     264For an example of a properly organized module, see Module File Example
     265(\S\ref{Foo.pm}).
    255266
    256267\subsubsection{Plain Old Documentation}
    257268\label{pod}
    258269
    259 This is the format for documentation in a \code{.pl} file after the
    260 \code{__END__} token and the \code{.pod} file that should accompany a module
    261 (\code{.pm}).
    262 
    263 e.g. for file Foo.pod:
    264 
    265 \verbatiminput{Foo.pod}
     270This is the format for documentation in a \code{.pod} file that should
     271accompany a module.
     272
     273For an example of a properly organized Pod, see Pod File Example
     274(\S\ref{Foo.pod}).
     275
    266276
    267277%------------------------------------------------------------------------------
     
    269279\section{Indentation}
    270280
    271 Four spaces should be used as the unit of indentation.  Spaces are
    272 recommended over tabs for indentation, but if tabs are used, the tabs
    273 stops must be set to 8 spaces, not 4.
     281Four spaces should be used as the unit of indentation; tabs are forbidden.
    274282
    275283\subsection{Line Length}
     
    367375When deactivating 3 or more lines of code an \code{if} statement should be used
    368376with a false boolean value.  The opening and closing of the \code{if} statement
    369 should be nest to the same depth as the surrounding code and the deactivated
     377should be nested to the same depth as the surrounding code and the deactivated
    370378section should be indented.
    371379
     
    380388\end{verbatim}
    381389
    382 Comments should be used to give overviews of code and provide
    383 additional information that is not readily available in the code
    384 itself. Comments should contain only information that is relevant to
    385 reading and understanding the program. For example, information about
    386 how the corresponding package is built or in what directory it resides
    387 should not be included as a comment.
    388 
    389 Discussion of nontrivial or non-obvious design decisions is
    390 appropriate, but avoid duplicating information that is present in (and
    391 clear from) the code. It is too easy for redundant comments to get out
    392 of date. In general, avoid any comments that are likely to get out of
    393 date as the code evolves.
    394 
    395 Note: The frequency of comments sometimes reflects poor quality of
    396 code. When you feel compelled to add a comment, consider rewriting the
    397 code to make it clearer.
    398 
     390\subsection{Implementation Comments}
     391
     392General rules:
     393
     394\begin{itemize}
     395\item
     396Comments should be used to give overviews of code and provide additional
     397information that is not readily available in the code itself. Comments should
     398contain only information that is relevant to reading and understanding the
     399program. For example, information about how the corresponding package is built
     400or in what directory it resides should not be included as a comment.
     401
     402\item
     403Discussion of nontrivial or non-obvious design decisions is appropriate, but
     404avoid duplicating information that is present in (and clear from) the code. It
     405is too easy for redundant comments to get out of date. In general, avoid any
     406comments that are likely to get out of date as the code evolves.
     407
     408\item
    399409Comments should not be enclosed in large boxes drawn with hashes or other
    400410characters.
    401 \hfil\break
     411
     412\item
    402413Comments should never include special characters such as form-feed and
    403414backspace.
    404  
    405 \subsection{Implementation Comment Formats}
     415\end{itemize}
     416
     417\emph{The frequency of comments sometimes reflects poor quality of code. When
     418you feel compelled to add a comment, consider rewriting the code to make it
     419clearer.}
    406420
    407421Programs can have three styles of implementation comments: single-line,
     
    455469additional spaces to cause trailing comments in adjoining lines to be
    456470vertically aligned.  Until such time as \code{perltidy} can following this
    457 convention or a replacement tool is located, code as formatted by
     471convention or a replacement tool is located, trailing comments as formatted by
    458472\code{perltidy} will be considered acceptable.}
    459473
    460474\subsection{API Comments}
    461 \label{DocComments}
    462475
    463476Plain Old Documentation format or Pod will be used to produce documentation of
     
    496509\begin{verbatim}
    497510    my ($verbose, $help);                   # Correct when the meaning is clear
     511    my ($foo, $bar) = @_;                   # Correct in a subroutine
    498512\end{verbatim}
    499513
     
    502516\begin{verbatim}
    503517    my ($foo, @fooArray);                   # AVOID!
     518\end{verbatim}
     519
     520\subsubsection{Scalars}
     521
     522Do not initialize more then one scalar per declaration.
     523
     524\begin{verbatim}
     525    my $foo = \$bar;                        # Correct
     526    my ($foo, $bar) = (1, 2);               # AVOID!
     527\end{verbatim}
     528
     529\subsubsection{Arrays}
     530
     531When assigning a large number of elements to an array a single column table
     532format should be used.
     533
     534\begin{verbatim}
     535    my @foo = (1, 'two', 3);                # Correct
     536
     537    my @foo = (                             # Correct
     538        1,
     539        'two',
     540        3,
     541        'four',
     542        5,
     543        'six',
     544        7,
     545        'eight',
     546        9,
     547        'ten'
     548    );
     549
     550    my @foo = (1, 'two', 3, 'four', 5, 'six', ...   # AVOID!
     551\end{verbatim}
     552
     553Consider using the \code{qw} operator when assigning strings to an array.
     554
     555\begin{verbatim}
     556    my @foo = qw( 1 two 3 );
     557
     558    my @foo = qw(
     559        1
     560        two
     561        3
     562        four
     563        5
     564        six
     565    );
     566\end{verbatim}
     567
     568\subsubsection{Hashes}
     569
     570When assigning a large number of elements to a hash a double column table
     571format should be used.
     572
     573\begin{verbatim}
     574    my %foo = (one => 1, two => 2);     # Correct
     575
     576    my %foo = (                         # Correct
     577        one   => 1,
     578        two   => 2,
     579        three => 3,
     580        four  => 4,
     581        five  => 5,
     582        six   => 6,
     583        seven => 7,
     584        eight => 8,
     585        nine  => 9,
     586        ten   => 10
     587    );
     588
     589    my %foo = (one => 1, two => 2, three => 3, ...  # AVOID!
    504590\end{verbatim}
    505591
     
    520606\end{verbatim}
    521607
    522 Note: This restriction does not apply to Perl's built in variables.
     608\emph{This restriction does not apply to Perl's built in variables.}
     609
     610\subsection{Package Variables}
     611
     612See When to Make Symbols Global (\S\ref{globals}).
    523613
    524614\subsection{Initialization}
    525615
     616General rules:
     617
     618\begin{itemize}
     619\item
    526620Try to initialize local variables where they're declared.
    527621
     622\item
    528623Do not initialize variables with an empty string or list - this is pointless.
    529624
     625\item
    530626A reason not to initialize a variable where it's declared is if the initial
    531627value depends on some computation occurring first.
    532628
    533 In some cases it may be necessary to initialize a variable to suppress
    534 a compiler warning; in this case a comment should explain the circumstances.
     629\item
     630In some cases it may be necessary to initialize a variable to suppress a
     631compiler warning; in this case a comment should explain the circumstances.
     632\end{itemize}
    535633
    536634\subsection{Placement}
     
    543641\subsection{Subroutine Declarations}
    544642
    545 When coding Perl subroutines the following formatting rules should be
     643When coding subroutines the following formatting rules should be
    546644followed:
    547645
     
    558656\item
    559657The first line after the opening brace should declare a list of lexical
    560 variables for input parameters and assign \code{@_} to it.
     658variables for input parameters and assign \code{shift} or \code{@_} to it.
    561659
    562660\item
     
    568666
    569667\item
    570 
     668Do not directly use the \code{@_} array.
     669
     670\item
    571671Do not nest named subroutines.
    572672\end{itemize}
    573673
    574674\begin{verbatim}
    575     sub subName
     675    sub subName                         # Correct
     676    {
     677        my $param = shift;
     678        ...
     679        return $val;
     680    }
     681
     682    sub subName                         # Correct
    576683    {
    577684        my ($param1, $param2, ...) = @_;
    578685        ...
    579 
    580686        return $val;
     687    }
     688
     689    sub subName                         # AVOID!
     690    {
     691        if ($_[0] eq "foo") {
     692        ...
    581693    }
    582694\end{verbatim}
     
    626738    return undef;                           # Correct
    627739    return;                                 # AVOID!
    628 
    629     return $myDisk->size;
    630 
    631     return ($size ? $size : $defaultSize);
    632 \end{verbatim}
    633 
    634 Note:  In the absence of an explicit return statement Perl will return the
     740    return $myDisk->size;                   # Correct
     741    return ($size ? $size : $defaultSize);  # Correct
     742\end{verbatim}
     743
     744\emph{In the absence of an explicit return statement Perl will return the
    635745results of the last statement executed.  A null \code{return} statement also
    636746causes the result of the last statement executed to be returned.  Relying on
    637747this behavior is likely to confuse maintenance programmers and therefore should
    638 be avoided.
     748be avoided.}
    639749
    640750\subsection{if, if-else, if-elsif-else Statements}
     
    766876Two blank lines should always be used in the following circumstances:
    767877\begin{itemize}
    768 \item Between sections of a source file
     878\item
     879Between sections of a source file
    769880\end{itemize}
    770881
     
    772883
    773884\begin{itemize}
    774 \item Between the local variables in a subroutine and its first statement
    775 
    776 \item Between logical sections inside a subroutine to improve readability
     885\item
     886Between the local variables in a subroutine and its first statement
     887
     888\item
     889Between logical sections inside a subroutine to improve readability
    777890\end{itemize}
    778891
     
    790903\end{verbatim}
    791904
    792 Note that a blank space should not be used between a subroutine name and its
    793 opening parenthesis. This helps to distinguish keywords from subroutine calls.
    794 
    795 \item
    796 A blank space should appear after commas in argument lists.
     905\emph{A blank space should not be used between a subroutine name and its
     906opening parenthesis. This helps to distinguish keywords from subroutine calls.}
     907
     908\item
     909A blank space should appear after commas in parameter lists.
     910
     911\begin{verbatim}
     912    subName(1, 2, 3);
     913\end{verbatim}
    797914
    798915\item
     
    828945\end{itemize}
    829946
     947Blank spaces should \textit{not} be used in the following circumstances:
     948
     949\begin{itemize}
     950\item
     951A dereferencing or method call should not have any blank spaces around the
     952\code{->} operator.
     953
     954\begin{verbatim}
     955    $myHashRef->{'foo'};
     956    $myObject->foo;
     957\end{verbatim}
     958
     959\end{itemize}
    830960%------------------------------------------------------------------------------
    831961
     
    843973\textbf{Rules for Naming} &
    844974\textbf{Examples} \\
     975\hline\\
     976
     977Script Files &
     978
     979The filenames of all scripts should be verbal phrases, in mixed case.  The
     980capitalized \code{.PL} suffix is reserved for ``build'' scripts.
     981
     982&
     983
     984\code{foo.pl}\hfil\break
     985\code{fooBar.pl}\hfil\break
     986\code{Makefile.PL}\hfil\break
     987
     988\\
     989
     990Module Files &
     991
     992The filenames of all modules should be verbal phrases, in mixed case, with the
     993first letter capitalized.
     994
     995&
     996
     997\code{Foo.pm}\hfil\break
     998\code{FooBar.pm}\hfil\break
     999
     1000\\
     1001
     1002Pod Files &
     1003
     1004The filenames of all stand-alone Pod should follow the same rules as module
     1005files.
     1006
     1007&
     1008
     1009\code{Foo.pod}\hfil\break
     1010\code{FooBar.pod}\hfil\break
     1011
     1012\\
    8451013
    8461014Subroutines &
     
    8731041
    8741042\code{$i;}\hfil\break
     1043\code{$i;}\hfil\break
    8751044\code{$c;}\hfil\break
    8761045\code{$myWidth;}\hfil\break
    877 \hfil\break
    8781046\code{$pseudo;}\hfil\break
    8791047\code{$myFiddleFactor;}\hfil\break
     
    8841052
    8851053Constant names should be in all capital letters and highly descriptive.  The
    886 \code{constant} pragma should be used to declare constants.  Note: `constants'
    887 created this way can not be interpolated inside of double quoted strings.
     1054\code{constant} pragma should be used to declare constants.
     1055\emph{``constants'' created this way can not be interpolated inside of double
     1056quoted strings.}
    8881057
    8891058&
    8901059\code{use constant PI => 3.14159265;}\hfil\break
    891 \code{use constant LENGTHS => qw(2, 4, 8);}\hfil\break
    892 \code{use constant CLASSES => (a => 1, b => 2);}\hfil\break
     1060\code{use constant LENGTHS => qw( 2, 4, 8 );}\hfil\break
     1061\code{use constant CLASSES => {a => 1, b => 2};}\hfil\break
    8931062
    8941063\\
     
    9011070&
    9021071
    903 \code{package PS::Metadata;}\hfil\break
    904 \code{package PS::Modules::Debias;}\hfil\break
    905 \code{package PS::Modules::FlatField;}\hfil\break
     1072\code{package PS::IPP::Metadata;}\hfil\break
     1073\code{package PS::IPP::Modules::Debias;}\hfil\break
     1074\code{package PS::MOPS::DB::Detections;}\hfil\break
     1075\code{package PS::MOPS::Util::MPC;}\hfil\break
    9061076
    9071077\\
     
    9291099
    9301100\subsection{When to Make Symbols Global}
     1101\label{globals}
    9311102
    9321103Only declare variables as package variables (\code{our}) if they are intended
     
    9361107\begin{verbatim}
    9371108    our $VERSION = '1.00';                  # Correct
     1109    our $localCounter;                      # AVOID! - should be lexical
    9381110
    9391111    use base qw( Exporter );
    940 
    9411112    our @EXPORT_OK = qw( $foo $bar );       # Correct
    942 
    943     our $localCounter;                      # AVOID!
    9441113\end{verbatim}
    9451114
     
    10791248\subsubsection{FileHandles}
    10801249
    1081 Don't use ``bare-words'' as filehandles except for \code{STDIN}, \code{STDOUT},
     1250Do not use ``bare-words'' as filehandles except for \code{STDIN}, \code{STDOUT},
    10821251and \code{STDERR}.
    10831252
     
    10851254    open(STDOUT, '>', $foo) or die "can not open STDOUT: $!";       # Correct
    10861255    open(my $fh, '>', $foo) or die "can not open file $foo: $!";    # Correct
    1087     open(FILE , '>', $foo) or die "can not open file $foo: $!";     # AVOID!
     1256    open(FILE, '>', $foo) or die "can not open file $foo: $!";      # AVOID!
    10881257\end{verbatim}
    10891258
     
    11001269\subsubsection{Chop vs. Chomp}
    11011270
    1102 Don't use \code{chop} to remove newline characters as it will remove any
     1271Do not use \code{chop} to remove newline characters as it will remove any
    11031272character (newline or not).
    11041273
    11051274\begin{verbatim}
    11061275    my $foo = "baz\n";                  # string with newline
    1107    
    11081276    chomp($foo);                        # removes "\n" - Correct
    11091277    chomp($foo);                        # chomping the same string twice is safe
    1110 
    11111278    chop($foo);                         # removes "z" - AVOID!
    11121279\end{verbatim}
     
    11251292
    11261293Use ``cuddled'' brackets \CODE.{}. when accessing a hash element.  It is
    1127 acceptable to use ``bare-words'' as a hash key (Note: this rule may be subject
    1128 to change).
     1294acceptable to use ``bare-words'' as a hash key (\emph{this rule may be subject
     1295to change}).
    11291296
    11301297\begin{verbatim}
     
    11471314\end{verbatim}
    11481315
    1149 Don't use \code{require} to prevent a module from exporting symbols into the
     1316Do not use \code{require} to prevent a module from exporting symbols into the
    11501317caller's namespace.  Instead, provide \code{use} with an empty parameter list.
    11511318
     
    11641331\subsubsection{Inheritance}
    11651332
    1166 Don't use the \code{@ISA} package variable for subclassing.  Instead, use the
     1333Do not use the \code{@ISA} package variable for subclassing.  Instead, use the
    11671334\code{base} pragma.
    11681335
     
    11771344``bare-word''.  Instead, use empty parentheses adjoined to the subroutine call.
    11781345
    1179 \code{subs} pragma is a last resort.
     1346\emph{Only use the \code{subs} pragma as a last resort.}
    11801347
    11811348\begin{verbatim}
     
    11871354\end{verbatim}
    11881355
     1356\subsubsection{Calling Methods}
     1357
     1358Leave the parentheses off method calls that aren't being passed parameters.
     1359
     1360\begin{verbatim}
     1361    $myObj->fooBar;                     # Correct
     1362    $myObj->fooBar($foo);               # Correct
     1363    $myObj->fooBar();                   # AVOID!
     1364\end{verbatim}
     1365
     1366\subsubsection{Quoting Strings}
     1367
     1368\begin{itemize}
     1369\item
     1370Unless variable interpolation needs to occur inside of a string or is likely to
     1371be needed in the future, use single quotes \code{''} instead of double quotes
     1372\code{""}.
     1373
     1374\item
     1375When possible use \code{END} as the termination token for ``\code{<<HERE}
     1376docs''.
     1377
     1378\begin{verbatim}
     1379    my $string = <<END
     1380    foo bar
     1381    bat baz
     1382    END
     1383\end{verbatim}
     1384
     1385\item
     1386Try to use the \code{qw} operator whenever possible.
     1387
     1388\item
     1389Consider using the \code{q} and \code{qq} operators instead of backslashes
     1390(\code{\}) when quoting strings that contain other quotes or blackslases.
     1391
     1392\item
     1393Consider using the \code{quotemeta} subroutine when handling strings that
     1394contain meta-characters.
     1395\end{itemize}
     1396
     1397\subsubsection{String Concatenation}
     1398
     1399Avoid use of the string concatenation operator (\code{.}) where it's
     1400unnecessary.
     1401
     1402\begin{verbatim}
     1403    $foo = "foo" . "bar";               # Correct
     1404    $foo .= "bar";                      # Correct
     1405    print "foo" , "bar";                # Correct
     1406    print "foo" . "bar";                # AVOID!
     1407\end{verbatim}
     1408
     1409\subsubsection{Regular Expressions}
     1410
     1411Use the ``extended'' regular expression syntax whenever practical.
     1412
     1413\begin{verbatim}
     1414    qr/^                                # Correct
     1415       ( -? (?:Bork\s*){0,9} , (?:Bork\s*){0,9}
     1416          , (?:Bork\s*){0,9} , (?:Bork\s*){0,9} )
     1417        - ( (?:Bork\s*){0,9} , (?:Bork\s*){0,9} )
     1418        - ( (?:Bork\s*){0,9} , (?:Bork\s*){0,9} )
     1419        T ( (?:Bork\s*){0,9} , (?:Bork\s*){0,9} )
     1420        : ( (?:Bork\s*){0,9} , (?:Bork\s*){0,9} )
     1421        : ( (?:Bork\s*){0,9} , (?:Bork\s*){0,9} )
     1422    $/ix;
     1423
     1424    qr/^(-?(?:Bork\s*){0,9},(?:Bork\s*){0,9},(?:Bork\s*){0,9},...$/i # AVOID!
     1425\end{verbatim}
     1426
    11891427\subsubsection{Subroutine Prototypes}
    11901428
     
    12021440
    12031441\section{Code Examples}
    1204 \subsection{Source File Example}
     1442\subsection{Script File Example}
     1443\label{foo.pl}
     1444
     1445\verbatiminput{foo.pl}
     1446
     1447\subsection{Module File Example}
     1448\label{Foo.pm}
     1449
     1450\verbatiminput{Foo.pm}
     1451
     1452\subsection{Pod File Example}
     1453\label{Foo.pod}
     1454
     1455\verbatiminput{Foo.pod}
     1456
     1457\subsection{Complete Program Example}
    12051458\label{SourceExample}
    12061459
     
    12091462
    12101463\verbatiminput{buildIndex.pl}
     1464
    12111465
    12121466%------------------------------------------------------------------------------
     
    12281482\verbatiminput{.perltidyrc}
    12291483
     1484
     1485%------------------------------------------------------------------------------
     1486
    12301487\section{Params::Validate}
    12311488\label{Params::Validate}
     
    12411498
    12421499An example \code{Params::Validate} named parameters validation spec taken from
    1243 the \code{DateTime} module.
    1244 
    1245 \begin{verbatim}
    1246     my $BasicValidate =
    1247         { year   => { type => SCALAR },
    1248           month  => { type => SCALAR, default => 1,
    1249                       callbacks =>
    1250                       { 'is between 1 and 12' =>
    1251                         sub { $_[0] >= 1 && $_[0] <= 12 }
    1252                       },
    1253                     },
    1254           day    => { type => SCALAR, default => 1,
    1255                       callbacks =>
    1256                       { 'is a possible valid day of month' =>
    1257                         sub { $_[0] >= 1 && $_[0] <= 31 }
    1258                       },
    1259                     },
    1260           hour   => { type => SCALAR, default => 0,
    1261                       callbacks =>
    1262                       { 'is between 0 and 23' =>
    1263                         sub { $_[0] >= 0 && $_[0] <= 23 },
    1264                       },
    1265                     },
    1266           minute => { type => SCALAR, default => 0,
    1267                       callbacks =>
    1268                       { 'is between 0 and 59' =>
    1269                         sub { $_[0] >= 0 && $_[0] <= 59 },
    1270                       },
    1271                     },
    1272           second => { type => SCALAR, default => 0,
    1273                       callbacks =>
    1274                       { 'is between 0 and 61' =>
    1275                         sub { $_[0] >= 0 && $_[0] <= 61 },
    1276                       },
    1277                     },
    1278           nanosecond => { type => SCALAR, default => 0,
    1279                           callbacks =>
    1280                           { 'cannot be negative' =>
    1281                             sub { $_[0] >= 0 },
    1282                           }
    1283                         },
    1284           locale    => { type => SCALAR | OBJECT,
    1285                          default => undef },
    1286           language  => { type => SCALAR | OBJECT,
    1287                          optional => 1 },
    1288         };
    1289 \end{verbatim}
    1290 
    1291 An example of how a validation spec is used in the \code{DateTime} module.
    1292 
    1293 \begin{verbatim}
    1294     use Params::Validate qw( validate validate_pos SCALAR BOOLEAN HASHREF OBJECT );
    1295     .
    1296     .
    1297 
    1298     sub new
    1299     {
    1300         my $class = shift;
    1301         my %p = validate( @_, $NewValidate );
    1302     .
    1303     .
     1500the \code{HTTP::Range}\footnote{HTTP::Range -
     1501http://search.cpan.org/~jhoblitt/HTTP-Range/} module.
     1502
     1503\begin{verbatim}
     1504    my %args = validate( @_,
     1505        {
     1506            request => {
     1507                type        => OBJECT,
     1508                isa         => 'HTTP::Request',
     1509            },
     1510            length => {
     1511                type        => SCALAR,
     1512                callbacks   => {
     1513                    'length is > 0'         => sub { $_[0] > 0 },
     1514                    'length is + integer'   => sub { $_[0] =~ /^\d+$/ },
     1515                },
     1516            },
     1517            segments => {
     1518                type        => SCALAR,
     1519                default     => 4,
     1520                callbacks   => {
     1521                    'segments is > 1'       => sub { $_[0] > 1 },
     1522                    'segments is + integer' => sub { $_[0] =~ /^\d+$/ },
     1523                    'segments is <= length' => sub { $_[0] <= $_[1]->{ 'length' } },
     1524                },
     1525            },
     1526        },
     1527    );
     1528
    13041529\end{verbatim}
    13051530
     
    13081533further details.
    13091534
     1535
     1536%------------------------------------------------------------------------------
     1537
    13101538\bibliographystyle{plain}
    13111539\bibliography{panstarrs}
Note: See TracChangeset for help on using the changeset viewer.