Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: How Much Is Too Much (on one line of code)?

by adrianh (Chancellor)
on Jun 19, 2007 at 04:15 UTC ( #621932=note: print w/replies, xml ) Need Help??

in reply to How Much Is Too Much (on one line of code)?

How do you feel about that code snippet?

Too much :-) Mostly because if the trailing if means I have to re-evaluate a fairly complex LHS after I've read it.

I'd also wonder about the hard-coded 'gbr'. Mostly I'd wonder if some other part of the system should "know" what the default country was. However, if this was the only place it was used I'd probably leave it inlined for the moment.

I'd probably re-write it as something like:

sub display_country { return unless my $country = $card->country; return '' if $country eq 'gbr'; return uc "[$country]"; }

with appropriate tweaks if the coercion of a false country to under/() in scalar/list was inappropriate in context.

Replies are listed 'Best First'.
Re: How Much Is Too Much (on one line of code)?
by vcTheGuru (Chaplain) on Jun 19, 2007 at 06:19 UTC
    I donít think it need to be re-written. To avoid confusion, I'd like to put two parenthesis and rewrite the code as

    my $country = $card->country; $country = (( $country eq 'gbr' ) ? '' : uc "[$country]" )if $country;
    If you treat every situation as a life-and-death matter,
    you'll die a lot of times.
    ~Dean Smith~

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://621932]
[stevieb]: it is exceptionally difficult I'm finding to debug a dist that is x-platform, where on each platform you're wrapping a different binary. Trying to co-ordinate a successful test run where tests are extensive is a nightmare, especially when the dist...
[stevieb]:'re testing is a test system itself. 10+ documented issues fixed, another half dozen found while fixing the original ones. I'm getting there...
[stevieb]: Then throw in changes to Windows that throws everything you trusted right out the window.
[shmem]: that's why it is called "Windows"

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2017-03-28 21:57 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (342 votes). Check out past polls.