> On Feb 26, 2004, at 11:47 AM, B McKee wrote: > > > Hi All, > > > > I'm slowly creating my Perl Masterpiece (tm) > > I'll let ya all giggle over it when I'm done :-) > > At any rate - It's done what I believe you call "top-down". > > I declare the subs, then have the code for the main program, > > then the subroutine code blocks. > > My question is what order should the subroutines appear in? > > Alphabetical? Order of appearance? Rough grouping by function? > > The fact that some subroutines may or may not call other subroutines > > and some of the subs are called by pretty much all the other subs > > makes it hard for me to decide what order would make it easiest to > > read. > > What's the 'standard'? > > I believe this is all pretty matter of opinion stuff. > > I have a habit of writing them in alphabetical order. I tell myself > it's so I always know where what I'm looking for is. > > Ready for the punch line? > > When I really want to jump straight to one of my subroutines, I use my > editor's "Function Pop-up Menu", which takes me right to it, no matter > where it is. It gets worse though. If I hold the Shift key when I > bring it up, it shows them in alphabetical order. Doh! So much for > logic. > > Use whatever makes sense to you. There's no right or wrong answer. >
I like most of this answer. I would add that you should drop the declarations of the subs, they are unneeded in Perl and can break some "features". This will help to some extent depending on your calling order. You may also want to read through: perldoc perlstyle For the most part I think alphabetical is silly, unless it *also* makes logical sense. I would say if you need alphabetical order to remember where things are then you need a better editor that lets you search faster, and alternatively provides code folding. Certainly in OOP, I prefer to keep my class and constructors towards the top, I would hate to have 'new' 3/4 of the way down, and have _init,init,_initialize (whatever) above it... OP, you may also want to consider dropping those subs into a library and extracting your main into a simple executable, but then there is some learning that will need to go along with that. perldoc perlsub may also have some gems but it has been awhile since I read it... http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>