Of course, of course, TIMTOWTDI is the glory of perl, and I am no heretic. But some times, in the dark before the dawn, I confess I find myself wishing there was Only One Way To Do It.
To take a trivial example. I output a guzillion on-the-fly pages to users, requesting info or prompting to action. Each one comes with a memo-style header giving the user's name and other relevant detail, just so everyone's sure we're all singing from the same hymn sheet. Up to now I output this with
use CGI;
use HTML:Template;
# .. then initialise $q and get input so we know what to do
sub Send_Header {
my $header_tmpl = HTML::Template->new(
filename => 'header.tmpl'
);
$header_tmpl->param(
header => shift,
to => shift,
date => substr(scalar gmtime time, 0, 10),
subject => shift,
);
print $header_tmpl->output();
}
print $q->header();
print $q->start_html(
-title => $title,
-style => {'src' => '../styles/main.css'},
);
Send_Header($header,$user,$subject)
# rest of message goes here
Which works fine. Then it occurred to me, as it might to anybody, that I could just as well put the
<TITLE> and
<STYLE> in the template. And that would work fine too. And doubtless by the time you've read this far you've thought of three other ways I could do the same thing, and they'd all work fine too.
This goes on all the time, and I'm not sure what to do about it. Sometimes one way really IS better than another, but even then the effort you go to in order to figure out WHICH is the best way probably means you were better off going with your first guess. Often, though, there are lots of different ways all of which are equally o.k.
And on occasions like that, I feel a bit like the donkey in the fable who starved to death between two piles of hay because he couldn't make up his mind which to eat.
<RAMBLING TYPE="PHILSOPHICAL">
I suppose this is the problem of our age in microcosm - we all have huge choices that our grandparents couldn't have dreamed of, and lots of us spend inordinate amounts of time trying to figure out which to do, rather than just doing it. As Sartre says (and I must say I think he mostly talks a load of nonsense, but this one acutely captures a psychological truth) Freedom Is Necessity. Lots of choices can be a kind of tyranny. Of course, one just has to have the gumption to turn the situation round, make the choice, and be doubly free. But in practice, it's quite hard work. And on a bad day, one longs for everything to be simple. If there were only one thing to do, one would feel completely free to do it.
</RAMBLING>
So in perl terms, for me it's as much a psychological as a technical problem. As I get better at this I'll be able to tell, and tell quickly, if there really is one way that's better than the others. But where there isn't, one's always going to need to make an existential leap and choose one rather than the other and move on. And for a perfectionist, this can be a difficult manoeuvre.
Maybe it's just me... but if not, I would be most interested to know whether and how other monks do this. When there's more than one way to do it, how do you decide how to do it?
§
George Sherston
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.