Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
To be honest, I prefer seeing idioms. It tells me that the user has a grasp on the elegance of the language.

Or a complete lack of a grasp, in my boss's case! ;-)

Knowing when to use Perl's idioms, and when to avoid them is the real point, I think.

For example, assigning to a typeglob just to get rid of a single level of indirection is a Perl idiom that's non-obvious, and not a wonderful idea if done for no reason. If you need to play with the typeglob syntax, it's there, and it's on rare occasions quite useful, but there's no reason to dabble lightly.

My boss didn't think so. He would frequently write stuff like this:

sub foo { my $x = shift; *y = $x; # Quick, what's he just done? He's just added something # to our namespace via aliasing, (and stripped a level # of indirection thereby), but what, exactly, has been # added? # Is it %y, @y, $y or even &y? What's he # up to? Arrrgh! # hundreds of lines later (a separate annoyance) # Ah, he aliased %y!!! $x must have been a *hashref* # He could have just written %y = %$x, but that # would be less efficient, and far less idiomatic foreach my $key ( keys %y) { bar($key); } }

Me, I'd just explictly dereference %$x, and skip the whole typeglob idiom, unless there was a significant reason not to do so. If I really wanted an automatic conversion, I'd probably use signatures instead. And if I were for some reason going to use the idiom, I'd point out at least the types (scalar, hash, array, or coderef) that I expected to be aliased by the idiom.

Making a section of a hash "local" is another of my boss's abuses of Perl idioms, in my opinion. Yes, you can make things "local". Wow, you can even make sections of things local. What a cute, quirky little way to express yourself: idiomatic perl at it's finest! It's barely even a documented feature!

And with it, you can call a function on a hash, and then go back, and undo what parts of the function did, based on a poorly documented set of flag settings! What fun!

Me? I'm just bitter, I guess. ;-) Too much burnout. :-(
--
AC


In reply to Re^4: seeds... by Anonymous Monk
in thread seeds... by SamCG

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 drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-03-29 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found