Think about Loose Coupling | |
PerlMonks |
Re: Getopt::Long good style?by wufnik (Friar) |
on Jul 28, 2004 at 12:50 UTC ( [id://378013]=note: print w/replies, xml ) | Need Help?? |
hola monseiur Skeeve. normally i would be absolutely the last person to wade in with any points re: style, mostly because my points re: code feng shui are invariably ignored, but being a heavy Getopt::Long user, i have one simple point i feel may be relevant. i frequently find i use functions, within the key GetOptions call of Getopt::Long, to actually parse command line arguments. one such script needs to get a list of variables which i want to calculate conditional probabilities for: here is he call to GetOptions. as you can see, it's long, and there are a number of functions that have to be called to deal with the vagaries of what i need & want. at least some of these vagaries are useful. witness the function addcp: this allows me to tell the script which conditional probabilities i need evaluated, ie: useful, but it requires the overhead of a function, which goes something like... not particularly complex - but there are a number of these functions that i call. and do i want them littering the call to GetOptions, where they not only look ugly, but prevent me breaking at them easily in my debugger? not really. if i were to implement all those functions anonymously, it would get to be a real mess there in GetOptions, and i would lose substantial brownie points if my grandmother took it into her head to look at the code. i mean, it's just not very neat and not very functional either, when it comes to debugging. now you may object that your scripts are rarely as complex as the above, and it looks nicer. but i would say that from a defensive coding perspective, you'd be better using real subs. if your script is a worthy brainchild, you will use it more, and want to see it grow. give it the room it needs!
...wufnik -- in the world of the mules there are no rules --
In Section
Seekers of Perl Wisdom
|
|