Michael G Schwern <schw...@pobox.com> wrote:
On 2012.5.13 11:36 AM, Peter Corlett wrote:
I'd like to throw in the fun breakage caused by the combination of adding
two unnecessary bits of syntactic sugar to Perl. Somebody decided that
auto-deref would be nice, so you can do "each $hashref" and "pop $arrayref".
And then somebody else clearly huffed a bit too much PHP and decided that
hash operations should also work on arrays where possible, even if it
doesn't make sense.[0] Quick now, what does "each $foo" do, buried 94 levels
deep in the call stack of your Enterprise Quality Software?

You have the history of that backwards.

Hash operations working on arrays are the unfortunate, ultimate evolution of
an unfortunate failed performance hack called pseudo-hashes where arrays were
made to act like hashes.

Assuming you're talking about the ability for the `keys`, `values`,
and `each` builtins to take either a %-prefixed hash or an @-prefixed
array as their argument, that's not quite true.  Pseudo-hashes were
finally removed in Perl 5.10, to universal rejoicing; extending
keys/values/each to arrays was done in 5.12.

(And furthermore, that extension was to permit a useful feature —
`each @array`, for iterating over the indexes and values of an array
in parallel — not as a performance hack, and not out of some misguided
notion that hashes and arrays are the same thing.  I know that because
it was at least partly my fault: I wrote the CPAN module where that
behaviour was prototyped, and I accidentally persuaded Nicholas Clark
to port it to the core.)

Then 5.14 acquired another new feature: the option to omit the @ or %
from the argument to certain builtins, including `keys`, `values`, and
`each`, by prototyping the relevant argument using the "+" character.
Since these two enhancements aren't entirely compatible, the current
situation is unfortunate: a "+"-prototyped argument must be an
unblessed array or hash ref — not a blessed reference, and not an
autovivifying undef (so `push $x, list` doesn't work on undef, even
though `push @$x, list` would work fine).

So much hate for tying the iterator to the data and not the op.

I fully share your hate for that.

--
Aaron Crane ** http://aaroncrane.co.uk/

Reply via email to