Previous Page
Next Page

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);

    Previous Page
    Next Page