Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

by talexb (Canon)
on Jun 18, 2007 at 18:31 UTC ( #621849=note: print w/replies, xml ) Need Help??


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

Without wanting to be influenced by the other comments, my opinion is that it's too much, without braces or a comment to make it clear in what order things happen, or why they are happening.

Without the braces I probably have to .. no, I have to look up what the precedence order is, or try it in the debugger. Yes, certainly after developing in Perl for ten years I should probably know that, but I don't. Also, the assignment to $country followed immediately by a re-assignment to $country isn't a style I love.

OK, (after trying it in the debugger) it does do the ternary first and the if statement within that .. that's what I expected.

To answer your question, no, this code is not clear.

Was there a comment explaining the business logic? The left side of my brain suggests ..

# Blank country field if Great Britain, otherwise upper # case country name within square brackets. Leave field # empty if country is undefined.
.. but the right side of my brain prevails, and provides a much better comment:
# Since we're mailing from GBR, only display the country # if it's not GBR, and leave a blank country field blank.

Above all, strive for clarity.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://621849]
help
Chatterbox?
and nobody stirs...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2017-12-14 01:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (382 votes). Check out past polls.

    Notices?