Re: mini-quiz
"Rob Kinyon" <[email protected]> Mon, 18 Jun 2007 16:47:07 -0400
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
On 6/18/07, Yitzchak Scott-Thoennes <[email protected]> wrote: > Things have been pretty quiet on this list, so I'm bringing up > a question I thought would interest you all. > > Ovid, on perlmonks, asks[1] if this code is doing too much on one line: > > my $country = $card->country; > $country = $country eq 'gbr' ? '' : uc "[$country]" if $country; > > How would you write it? Feel free to respond here or in the > perlmonks thread. No need to wait 60 hours. That whole "Cannot be GBR" thing sounds like something that needs encapsulated and heavily commented somewhere. Without knowing more about the app in question, I'm not sure where the right place to put this little slice of chaos. Depending on how $card is created, I'd be tempted to subclass it for this specific situation and put that crap in there. At that point, the silliness is hidden and all you probably don't need to put $card->country into a temp var. If that's not possible, then this class should have a getCountry() method that makes this silliness hidden. Either way, the problem isn't the tail-if on a complex statement. The problem is the requirements that led the poor programmer into such silliness. Rob