Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Re: where do you put your subsby Trimbach (Curate) |
on Mar 08, 2002 at 13:10 UTC ( [id://150301]=note: print w/replies, xml ) | Need Help?? |
Subs at the top? Subs at the bottom? What's next? Should we discuss whether toilet paper should roll from the top or bottom? :-D Seriously, DeMerphq gives some excellent reasons why you might put your subs at the top, but I've also seen lots of good reasons why you'd want your subs at the bottom. The "unintended global" problem is often a feature, not a bug: yes, I do use global variables (judiciously, and deliberately, and with full knowledge of what I'm doing) and when I do I declare them... at the top of my program. This makes perfect sense to me, as the order of events is:
The subs are all black boxes (mostly, except where they use the package globals), which means (in my mind) it shouldn't make the slightest bit of difference where they appear in code order. They aren't executed "in order" so order becomes immaterial. But you know, that's what makes sense to me. Some people are completely allergic to () so they declare their subs first. I don't mind typing "foo()" so I don't care. If you don't like globals (and want to go whatever means necesary to keep from using them, either on purpose or accidentally) hey, more power to ya. I think they're kinda spiffy, and my code is brutally consistent as to how and when I declare them and use them. All in all I think perlstyle is silent on this because it really is a matter of taste, and TMTOWTDI. Perhaps next we'll discuss proper tab indentation. :-D Gary Blackburn
In Section
Seekers of Perl Wisdom
|
|