'Plan to write your library twice, you will anyway'
which means, because you aren't really sure what you want, or how to do it properly, your first attempt will be OK, but you'll soon wish you had done it differently. Dont worry, do it again, using the lessons AND experience you now have.
'Try to write the interface in a way you think wont need to change'
Hard to do, especially if this is your first attempt. Generalise what you are trying to do. Dont write a 'calculate_fuel_tax()' function or method. Perhaps an 'apply_tax(tax_type)' method is more general, with the _implementation_ doing the gritty work for each tax type.
'Write test cases for EVERYTHING in your library'
In short, if you decide at some point to replace the guts of a method (or entire library), a regression test suite gives you a lot of confidence your dependent code and libraries will still work. Its like replacing your car engine from petrol to electric - as long as all the controls still work the same way, you can drive it exactly the same way.
Use the excellent Test::More and ExtUtils::MakeMaker modules - learn to use them very well, it is well worth the effort - study existing CPAN modules for how they use them
A technical suggestion
'Use hashes as your parameters to methods/functions'
The code becomes self documenting, and more mnemonic. Which is easier to understand and remember
ormy $result = apply_tax(type => 'fuel', state => 'CA', period_start => '01/02/2004', period_end => '12/02/2004');
my $result = apply_tax('fuel', 'CA', '01/02/2004', '12/02/2004');
+++++++++++++++++
#!/usr/bin/perl
use warnings;use strict;use brain;
In reply to Re: Perl Templates
by leriksen
in thread Perl Templates
by ellem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |