IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2398


Ignore:
Timestamp:
Nov 22, 2004, 4:38:16 PM (22 years ago)
Author:
jhoblitt
Message:

break out the examples for foo.pl, Foo.pm, & Foo.pod into separate files
add subsections for $_, filehanldles, & system calls

Location:
trunk/doc/misc
Files:
3 added
1 edited

Legend:

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

    r2381 r2398  
    1 %%% $Id: perlCodeConventions.tex,v 1.22 2004-11-17 20:51:07 jhoblitt Exp $
     1%%% $Id: perlCodeConventions.tex,v 1.23 2004-11-23 02:38:16 jhoblitt Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    185185e.g. for file \file{foo.pl}:
    186186
    187 \scriptsize
    188 \code{#!/usr/bin/perl}\\
    189 \\
    190 \code{# Copyright (C) 2004  Joshua Hoblitt}\\
    191 \code{#}\\
    192 \code{# $}\code{Id$}\\
    193 \normalsize
    194 \begin{verbatim}
    195     use 5.008005;                           # optional
    196 
    197     use strict;                             # not optional
    198     use warnings;                           # not optional
    199 
    200     use Foo qw( $bar );                     # import $bar into our namespace
    201 
    202     use constant MAXFOO => 3;               # maximum number of foos
    203 
    204     my $baz;                                # is a lexical variable in the top level scope
    205 
    206     sub fuu
    207     {
    208 
    209     }
    210 
    211     __END__
    212 
    213     ...
    214 \end{verbatim}
     187\verbatiminput{foo.pl}
    215188
    216189\subsubsection{Perl Modules}
     
    261234e.g. for file \file{Foo.pm}:
    262235
    263 \scriptsize
    264 \code{# Copyright (C) 2004  Joshua Hoblitt}\\
    265 \code{#}\\
    266 \code{# $}\code{Id$}\\
    267 \normalsize
    268 \begin{verbatim}
    269     package Foo;
    270 
    271     use 5.008005;                           # optional
    272 
    273     use strict;                             # not optional
    274     use warnings;                           # not optional
    275 
    276     use base qw( Baz );                     # become a subclass of Baz
    277 
    278     use Foo qw( $bar );                     # import $bar into our namespace
    279 
    280     use constant MAXFOO => 3;               # maximum number of foos
    281 
    282     my $baz;                                # is a lexical variable in the top level scope
    283 
    284     sub fuu
    285     {
    286 
    287     }
    288 
    289     1;
    290 
    291 __END__
    292 \end{verbatim}
     236\verbatiminput{Foo.pm}
    293237
    294238\subsubsection{Plain Old Documentation}
     
    300244e.g. for file Foo.pod:
    301245
    302 \begin{verbatim}
    303     =pod
    304 
    305     =head1 NAME
    306 
    307     Foo - Does something with Baz.
    308 
    309     =head1 SYNOPSIS
    310 
    311         use Foo;
    312 
    313         ...
    314 
    315     =head1 DESCRIPTION
    316 
    317     More details about what this modules does with Baz.
    318 
    319     =head1 USAGE
    320 
    321     =head2 Import Parameters
    322 
    323     This module accepts no arguments to it's C<import> method and exports no
    324     I<symbols>.
    325 
    326     =head2 Methods
    327 
    328     =head3 Class Methods
    329 
    330     =over 4
    331 
    332     =item * methodOne
    333 
    334     details of methodOne
    335 
    336     =item * methodTwo
    337 
    338     details of methodTwo
    339 
    340     ...
    341 
    342     =back
    343 
    344     =head1 SUPPORT
    345 
    346     Where to get help.
    347 
    348     =head1 AUTHOR
    349 
    350     Principle authors and contact info.
    351 
    352     =head1 COPYRIGHT
    353 
    354     Copyright (C) 2004  Robert Lupton.  All rights reserved.
    355 
    356     This program is free software; you can redistribute it and/or modify it under
    357     the terms of the GNU General Public License as published by the Free Software
    358     Foundation; either version 2 of the License, or (at your option) any later
    359     version.
    360 
    361     This program is distributed in the hope that it will be useful, but WITHOUT ANY
    362     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    363     PARTICULAR PURPOSE.  See the GNU General Public License for more details.
    364 
    365     You should have received a copy of the GNU General Public License along with
    366     this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    367     Place - Suite 330, Boston, MA  02111-1307, USA.
    368 
    369     The full text of the license can be found in the LICENSE file included with
    370     this module, or in the L<perlgpl> Pod as supplied with Perl 5.8.1 and later.
    371 
    372     =head1 SEE ALSO
    373 
    374     L<Bar::Baz>
    375 
    376     =cut
    377 \end{verbatim}
    378 
     246\verbatiminput{Foo.pod}
    379247
    380248%------------------------------------------------------------------------------
     
    643511\subsection{Initialization}
    644512
    645 Try to initialize local variables where they're declared.  Do not initalize
     513Try to initialize local variables where they're declared.  Do not initialize
    646514variables with an empty string or list - this is pointless.
    647515
     
    11801048\end{verbatim}
    11811049
     1050\subsection{\$\_}
     1051
     1052Use of the ``default'' variable (\code{$_}) should be avoided.
     1053
     1054\begin{verbatim}
     1055    my $foo =~ /(foo.*)/;                   # Correct
     1056    foreach my $foo (@bar) {}               # Correct
     1057    /(foo.*)/;                              # AVOID!
     1058    $_ = ~/(foo.*)/;                        # AVOID!
     1059\end{verbatim}
     1060
     1061\subsection{FileHandles}
     1062
     1063Don't use ``bare-words'' as filehandles except for \code{STDIN}, \code{STDOUT},
     1064or \code{STDERR}.
     1065
     1066\begin{verbatim}
     1067    open(STDOUT, '>', $foo) or die "can not open STDOUT: $!";   # Correct
     1068    open(my $fh, '>', $foo) or die "can not open file $foo: $!";# Correct
     1069    open(FILE , '>', $foo) or die "can not open file $foo: $!"; # AVOID!
     1070\end{verbatim}
     1071
     1072\subsection{System Calls}
     1073
     1074Always check the return code of system calls.
     1075
     1076\begin{verbatim}
     1077    open(my $fh, '>', $foo) or die "can not open file $foo: $!";    # Correct
     1078    close($fh) or die "can not close file $foo: $!";                # Correct
     1079    chdir($foo);                                                    # AVOID!
     1080\end{verbatim}
     1081
    11821082%------------------------------------------------------------------------------
    11831083\appendix                               %Begin Appendices
     
    11991099
    12001100\code{pertidy} is a Perl specific code ``beautifier'' with functionality
    1201 similar to \code{indent} or \code{astyle}.  It is freely avalible from
     1101similar to \code{indent} or \code{astyle}.  It is freely available from
    12021102\code{http://perltidy.sourceforge.net/}.
    12031103
     
    12051105\file{.perltidyrc} file in your home directory.
    12061106
    1207 Example \file{.perltidyrc} file to acheive the Perl code convention:
     1107Example \file{.perltidyrc} file to achieve the Perl code convention:
    12081108
    12091109\verbatiminput{.perltidyrc}
Note: See TracChangeset for help on using the changeset viewer.