[Israel.pm] Perl vs. Ruby on Two Idioms

Jason Elbaum jason.elbaum at gmail.com
Sun Jun 22 02:24:14 PDT 2008


On Sun, Jun 22, 2008 at 12:06 PM, Shlomi Fish <shlomif at iglu.org.il> wrote:

> Yes, but this takes two statement. Cognitively, it is one operation and so I
> want to do it in a single statement.

How is declaring and filling a variable "one operation"? Sounds like two to me.

If you want to do it in a single statement, use a function:

sub list_to_set {
  return map { $_ => 1 } @_;
}

my %h = list_to_set(@a);

That's what programming abstractions are for.



> I have no problem reading the Perl solution, and neither would any
> intermediate Perl programer. And doesn't the map call build a long list?

Not everyone who has to maintain Perl code is an intermediate Perl programmer.


> Why are people so obsessed with the "clarity" of such small scopes?

Because maintenance programmers have to read and understand every line
of code they touch, even if they're rusty in the idioms of the
language. Every time they have to mentally unpack obscure syntax, it
slows them down and increases the chances of error. Clear code is
better than compact code.


Like I said, it depends on the level of Perl experience you can safely
assume from the developers.

Regards,

Jason Elbaum



More information about the Perl mailing list