Changeset 2333
- Timestamp:
- Nov 10, 2004, 4:00:42 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/doc/misc/perlCodeConventions.tex (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/misc/perlCodeConventions.tex
r2332 r2333 1 %%% $Id: perlCodeConventions.tex,v 1. 2 2004-11-11 01:55:58jhoblitt Exp $1 %%% $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $ 2 2 \documentclass[panstarrs]{panstarrs} 3 3 … … 155 155 # Copyright (C) 2004 Joshua Hoblitt 156 156 # 157 # $Id: perlCodeConventions.tex,v 1. 2 2004-11-11 01:55:58jhoblitt Exp $157 # $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $ 158 158 159 159 use 5.008005; # optional … … 212 212 # Copyright (C) 2004 Joshua Hoblitt 213 213 # 214 # $Id: perlCodeConventions.tex,v 1. 2 2004-11-11 01:55:58jhoblitt Exp $214 # $Id: perlCodeConventions.tex,v 1.3 2004-11-11 02:00:42 jhoblitt Exp $ 215 215 216 216 package Foo; … … 471 471 \end{verbatim} 472 472 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} 500 474 501 475 Avoid \code{local} declarations that hide user declared variables from higher … … 510 484 local $count; 511 485 ... 486 } 487 \end{verbatim} 488 489 Note: This restiction does not apply to Perl's built in variables. 490 491 \subsection{Initialization} 492 493 Try to initialize local variables where they're declared. The only 494 reason not to initialize a variable where it's declared is if the 495 initial value depends on some computation occurring first. 496 497 In some cases it may be necessary to initialize a variable to suppress 498 a compiler warning; in this case a comment should explain the circumstances. 499 500 \subsection{Placement} 501 502 Variables should ordinarily be declared at the top of the block in 503 which they appear, unless there is some reason to declare them later. 504 This allows them to be initialised as they are created, and naturally 505 associates 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++; 512 516 } 513 517 \end{verbatim}
Note:
See TracChangeset
for help on using the changeset viewer.
