http://qs1969.pair.com?node_id=502728


in reply to Re^3: seeds...
in thread seeds...

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