Section 2.17. Non-Terminal Expressions


2.17. Non-Terminal Expressions

Factor out long expressions in the middle of statements.

The previous guideline applies only if the long expression to be broken is the last value in a statement. If the expression appears in the middle of a statement, it is better to factor that expression out into a separate variable assignment. For example:

      my $next_step = $steps[-1]                     + $radial_velocity * $elapsed_time                     + $orbital_velocity * ($phase + $phase_shift)                     - $DRAG_COEFF * $altitude                     ;     add_step( \@steps, $next_step, $elapsed_time); 

rather than:

     add_step( \@steps, $steps[-1]                        + $radial_velocity * $elapsed_time                        + $orbital_velocity * ($phase + $phase_shift)                        - $DRAG_COEFF * $altitude                        , $elapsed_time); 



Perl Best Practices
Perl Best Practices
ISBN: 0596001738
EAN: 2147483647
Year: 2004
Pages: 350
Authors: Damian Conway

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net