Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I think that what you may be missing is that vertical space savings often enhance readability in terms of making it possible to see the whole forest at once.

In the same vein, I've seen (mostly beginning C++) people say that printf-formatted strings are too much like line noise, and everything should really be formatted through the expressive cout format, with operators to change the number of digits of precision, etc.

The same people might well complain about pack. The common lisp community often fields complaints about how terribly obscure the syntax is to format.

The point is that compressing stuff that's not terribly important to understanding the whole improves understanding of the code overall. Good code should read like stuff you want to read, and my eyes glaze over with too much pointless verbosity. (Usually, my eyes glazing is a sign that the code I'm reading suffers from severe cut-and-paste and really needs to be refactored to deal with multiple cases in a more generic fashion.)

You've obviously encountered several bad uses of the ?: operator. Allow me to present at least one good one:

my $numspells = ($doDeanStuff ? 1 : 0) + ($doSeamusStuff ? 1 : 0) + ($doHarryStuff ? 2 : 0) # Harry's stuff takes multipl +e spells + ($doRonStuff ? 1 : 0) + ($doSeverusStuff ? 5 : 0); # it's really complicated print "Budget for this incantation is $numspells spells\n";
Now in this case I'm sure you could do:
my $numspells = 0; $numspells += 1 if ($doDeanStuff); $numspells += 1 if ($doSeamusStuff); $numspells += 2 if ($doHarryStuff); # Harry's stuff takes multiple sp +ells $numspells += 1 if ($doRonStuff); $numspells += 5 if ($doSeverusStuff); # it's really complicated
But I think that the first version is easier - or at least, faster - to read. (more whitespace per bit of meaning) And code that's faster to read is more likely to get read in full before someone makes changes to it.

(Yeah, I'm just getting around to reading book 6 now)

-- @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

In reply to Re^3: Ternary operators: a hinderance, not a help by fizbin
in thread Ternary operators: a hinderance, not a help by Tanalis

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 examining the Monastery: (6)
As of 2024-04-18 19:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found