in reply to Re: Re: Re: Re: where do you put your subs
in thread where do you put your subs

You find having ALL variables used outside subs shared EASIER TO DEBUG? Might be the case for simple CGI scripts, or programs of which the entire source fits on a single screen, but it has bitten many people.

Even Merlyn puts his subs last in his Web Techniques columns, which are deliberately aimed at instructing others on how to do things the right way.

And I think merlyn does it the wrong way. Besides, what merlyn does isn't automatically the right way to do it. Actually, I find much of his code written in an awful style, but I guess he'd say the same when reading my code. (OTOH, it's really hard to have good style when you're writing simple stand-alone web applications.)

As for the program logic you describe at the end of your post, I've seen real good, and very stylish programs like this:
my $qwerty; # Description { my ($foo, $bar); code; code; code; } # And now we're going to ... { my ($xyzzy); code; code; } # Etcetera... { code; code; code; }
, which is great to look at, easy to read and very maintaible. You could do the same with a lot of closures, and thus bundle subs with the location of use.

44696420796F7520732F2F2F65206F
7220756E7061636B3F202F6D736720
6D6521203A29202D2D204A75657264

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: where do you put your subs
by Trimbach (Curate) on Mar 08, 2002 at 16:16 UTC
    And I think merlyn does it the wrong way. Besides, what merlyn does isn't automatically the right way to do it. Actually, I find much of his code written in an awful style, but I guess he'd say the same when reading my code.
    Ah, then that's the point now, isn't it... there's enough difference of opinion that it's hard to say who's "right".
    As for the program logic you describe at the end of your post, I've seen real good, and very stylish programs like this:
    Yeah, so have I... I really like the block enclosure style, but now we're not talking about subs anymore. The flow of the program is still linear in your example, and is perfectly fine in my book. When you intersperse subroutines in with logic then your program execution stops being linear and becomes non-linear, meaning you're bouncing around all over the place trying to read the dang thing. Not good. And if you're going to bundle your subs with location of use, and wrap the whole thing in a closure, you probably ought to be changing packages, too. ;-D

    Gary Blackburn
    Trained Killer