[Phoenix-pm] poll: top or bottom?
Michael Friedman
friedman at highwire.stanford.edu
Fri Apr 7 20:03:43 PDT 2006
To be honest, I don't put a main() around the main code. It's a
script, so it's just going to run top to bottom. On the other hand, I
almost always put any functions into other modules. That way everyone
at my office can reuse them without having to copy code.
It also makes a nice separation: code that does the work goes into a
module, wrapper/driving code goes into a script. And if I need a CGI
that does the same thing as a script, all I have to do is write a new
wrapper around the already-written module.
But it's Perl, so TIMTOWTDI. Yay!
-- Mike
On Apr 7, 2006, at 4:38 PM, Brock wrote:
> I think I got into the habit of putting a sub called main() at the
> bottom through influence of C and Pascal. In Pascal you can't do it
> any
> other way.
>
> That said, I don't stick to it consistently, and sometimes my main
> logic
> (which might only be a few lines) I put outside of anything right
> at the
> top.
>
> But I've not been known for my "Best Practice"s. :)
>
> --Brock
>
> On 2006.04.07.16.02, Metz, Bobby W, WCS wrote:
> | It's Perl so anything goes and we won't shoot you for it, well
> some of
> | us anyway.
> |
> | That said, "bottom" to your 1st ? and "no" to your 2nd. I find
> those
> | folks who came from a C background or studied programming more in
> | college tend to start with functions @ the top. I was one of
> those, but
> | I always eschewed having to scroll through pages of code just to
> get to
> | the begining, search features or not. But that's just me.
> |
> | B
> |
> | -----Original Message-----
> | From: phoenix-pm-bounces+bwmetz=att.com at pm.org
> | [mailto:phoenix-pm-bounces+bwmetz=att.com at pm.org]On Behalf Of Corey
> | Saltiel
> | Sent: Friday, April 07, 2006 1:55 PM
> | To: phoenix-pm at pm.org
> | Subject: [Phoenix-pm] poll: top or bottom?
> |
> |
> |
> | Where do you guys place your subroutines in scripts?
> |
> | And what do you usually prefer to call the subroutine that kicks
> things
> | off,
> | i.e. 'main()', 'begin()'?
> |
> | I've always put my subroutines at the top, right after the basic
> setup
> | logic
> | ( declaring pragmas and modules, and whatever global vars, etc ),
> then I
> |
> | throw the call to the entering/main subroutine at the very
> bottom of
> | the
> | script, underneath the subroutines -- but I tend to be switch
> between
> | calling the entering subroutine either: main() or begin() - out
> of sheer
> |
> | indecision.
> |
> | Like so:
> |
> | #!/usr/bin/perl
> | use warnings;
> | use strict;
> |
> | use ACME;
> | use Blah;
> |
> | my ( $globals, $go, $here ); # minimal or non-existant
> |
> | $globals = '';
> |
> | $go = '';
> |
> | $here = ''
> |
> |
> | sub foo { }
> |
> | sub bar { }
> |
> | sub snafu {}
> |
> | sub begin {}
> |
> |
> | begin();
> |
> |
> | Anyhow, just curious! Obviously mostly a matter of subjective
> opinion,
> | but
> | interesting none-the-less.
> |
> |
> | Beers,
> |
> | Corey
> | _______________________________________________
> | Phoenix-pm mailing list
> | Phoenix-pm at pm.org
> | http://mail.pm.org/mailman/listinfo/phoenix-pm
> | _______________________________________________
> | Phoenix-pm mailing list
> | Phoenix-pm at pm.org
> | http://mail.pm.org/mailman/listinfo/phoenix-pm
> _______________________________________________
> Phoenix-pm mailing list
> Phoenix-pm at pm.org
> http://mail.pm.org/mailman/listinfo/phoenix-pm
---------------------------------------------------------------------
Michael Friedman HighWire Press
Phone: 650-725-1974 Stanford University
FAX: 270-721-8034 <friedman at highwire.stanford.edu>
---------------------------------------------------------------------
More information about the Phoenix-pm
mailing list