Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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:

if ( $obj->show_phone ) { $obj->print_phone_number; }
Here's some code where that probably is best:
# Validate the phone according to basic U.S. rules if ( $phone =~ s/^(1-)?(\d\d\d-?\d\d\d-?\d\d\d\d)$/ ) { $phone = $2; $phone =~ s/-//g; # Strip dashes $obj->set_phone( $2 ); } else { $obj->error( "Invalid phone number" ); } if ( $obj->show_phone ) { $obj->print_phone_number; }
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.

$obj->print_name; $obj->print_address; $obj->print_phone_number if $self->showphone; $obj->print_email_address;

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:

$obj->print_name; $obj->print_address; if ( $obj->show_phone ) { $self->print_phone_number; } $obj->print_email_address;
Blech.

I think rule two of Perl, after TMTOWTDI, should be "It all depends."

xoxo,
Andy
--
<megaphone> Throw down the gun and tiara and come out of the float! </megaphone>


In reply to Re: Conditional style (if, &&) query by petdance
in thread Conditional style (if, &&) query by traveler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-26 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found