IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2333


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

separate subsection for local variables

File:
1 edited

Legend:

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

    r2332 r2333  
    1 %%% $Id: perlCodeConventions.tex,v 1.2 2004-11-11 01:55:58 jhoblitt Exp $
     1%%% $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    155155# Copyright (C) 2004  Joshua Hoblitt
    156156#
    157 # $Id: perlCodeConventions.tex,v 1.2 2004-11-11 01:55:58 jhoblitt Exp $
     157# $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $
    158158
    159159use 5.008005;   # optional
     
    212212# Copyright (C) 2004  Joshua Hoblitt
    213213#
    214 # $Id: perlCodeConventions.tex,v 1.2 2004-11-11 01:55:58 jhoblitt Exp $
     214# $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $
    215215
    216216package Foo;
     
    471471\end{verbatim}
    472472
    473 \subsection{Initialization}
    474 
    475 Try to initialize local variables where they're declared.  The only
    476 reason not to initialize a variable where it's declared is if the
    477 initial value depends on some computation occurring first.
    478 
    479 In some cases it may be necessary to initialize a variable to suppress
    480 a compiler warning; in this case a comment should explain the circumstances.
    481 
    482 \subsection{Placement}
    483 
    484 Variables should ordinarily be declared at the top of the block in
    485 which they appear, unless there is some reason to declare them later.
    486 This allows them to be initialised as they are created, and naturally
    487 associates their declaration with their use.
    488 
    489 
    490 Indexes of loops should usually be declared on the line above loop statement.
    491 
    492 \begin{verbatim}
    493 my $i = 0;
    494 for (i < $maxLoops) {
    495     # do stuff
    496 
    497     $i++;
    498 }
    499 \end{verbatim}
     473\subsection{Local Variables}
    500474
    501475Avoid \code{local} declarations that hide user declared variables from higher
     
    510484    local $count;
    511485    ...
     486}
     487\end{verbatim}
     488
     489Note: This restiction does not apply to Perl's built in variables.
     490
     491\subsection{Initialization}
     492
     493Try to initialize local variables where they're declared.  The only
     494reason not to initialize a variable where it's declared is if the
     495initial value depends on some computation occurring first.
     496
     497In some cases it may be necessary to initialize a variable to suppress
     498a compiler warning; in this case a comment should explain the circumstances.
     499
     500\subsection{Placement}
     501
     502Variables should ordinarily be declared at the top of the block in
     503which they appear, unless there is some reason to declare them later.
     504This allows them to be initialised as they are created, and naturally
     505associates their declaration with their use.
     506
     507
     508Indexes of loops should usually be declared on the line above loop statement.
     509
     510\begin{verbatim}
     511my $i = 0;
     512for (i < $maxLoops) {
     513    # do stuff
     514
     515    $i++;
    512516}
    513517\end{verbatim}
Note: See TracChangeset for help on using the changeset viewer.