in reply to Subroutines versus straight top to bottom scripts

How about comprehensibility?

Subroutines as short as possible; hopefully never longer than what fits on screen. Smaller is better ( < 20-25 lines?).

With subroutines, testing becomes easier or even feasible.

(And yes, reusability: you'll end up with subs anyway, if the script will have any life beyond running once.)

  • Comment on Re: Subroutines versus straight top to bottom scripts

Replies are listed 'Best First'.
Re^2: Subroutines versus straight top to bottom scripts
by salva (Canon) on Jun 03, 2005 at 12:10 UTC
    reading your comment I become curious about how many lines I put on my subs and wrote this little script: counting the lines on your subs.

    Running it over my code I have found that most of my subs are below 10 lines, and the most frequent size is 1 line (~18%), even when I use mcoder or Class::MethodMaker to generate common accessors that are not counted!

Re^2: Subroutines versus straight top to bottom scripts
by tilly (Archbishop) on Jun 04, 2005 at 06:44 UTC
    While my subroutines tend to be short, actual data on benefits of short subroutines is more ambiguous. In fact there is some data saying that short subroutines are counterproductive. Obviously this doesn't match widely held current beliefs. See Short routines matter more in OO? for some guesses as to why this might be.