Welcome to the Monastery | |
PerlMonks |
Re: Conditional style (if, &&) queryby petdance (Parson) |
on Oct 17, 2001 at 08:04 UTC ( [id://119326]=note: print w/replies, xml ) | Need Help?? |
Everything depends entirely on the specific context. That's
the beauty of TMTOWTDI.
I usually try to sound as English-like as possible, and keep in mind what I'm trying to emphasize: the test or the action? There's no One Right Way, even within the same program or even the same block of code. Go with what makes the most sense for the specific piece of code. Also, consider the surrounding code. Something as simple as conditionally printing a phone number can depend greatly on why it's doing it. The "standard" way might be: Here's some code where that probably is best: We check the phone number, and make sure it's a valid format, and then when we're done, we might print the phone number. Whether we print or not is incidental to the rest of the block. But consider this instance where the context is entirely different.
Here, it's more appropriate to show that we're printing a bunch of information, and the phone number is optional. Writing it the "old way", with the phone number block taking three lines, would break up the visual flow, like so: Blech. I think rule two of Perl, after TMTOWTDI, should be "It all depends."
xoxo,
In Section
Seekers of Perl Wisdom
|
|