Watch for Ice

Too much punctuatel of on?

Programmers say they hate Perl because it has too much punctuation. I have no idea what they're talking about. Consider the following code I wrote:

    sub { [ @{$_[0]} => map { $_ ? @$_ : () } @{$_[1]} ] }

Now what's wrong with that? A model of clarity.
  • Current Mood: amused amused
wow and here I was hating c++ because the semi-colons annoyed me
Trust me, that's an extreme case because I'm doing some really funky stuff with a lexer/parser. If you're familiar with Perl, it makes sense, but it's still not common.
It makes sense in the "yes, you can understand independently what that snippet does." Of course, without the context, understanding why it does it is a different matter.
I'm sure I'll be able to figure it out what it does eventually. Right now it looks like you sneezed while typing. ;)
Deparse agrees.

$ perl -MO=Deparse -e 'sub { [ @{$_[0]} => map { $_ ? @$_ : () } @{$_[1]} ] }'
sub {
    [@{$_[0];}, map({$_ ? @$_ : ();} @{$_[1];})];
}
;
-e syntax OK
$

That's a switch. Usually Deparse makes code easier to read.

Curiously, I was using deparse within this code yesterday. I was slinging around a lot of anonymous coderefs and I needed to whip out deparse to tell me which coderefs were where. Ugh!
If you need to use deparse on your own code, this is a good sign that you may want to create more (named) levels of abstraction.
Have you read Higher Order Perl yet? If you get to the parsing chapter, you can see some examples where tons of code refs are being passed around and if you lose track of what's where, it's a nightmare.

Fabulous book, by the way.
man, i always thought the punctuation was one of the things that made perl interesting. then again, i have this habit of abusing [punctuation] horribly in normal english, so. :/
scary thing, i was able to parse that.

been fighting a readability battle with one of our developers ... he seems to think that 100 map statements are easier to read than well written, formatted sql:

SELECT foo, bar

vs

SELECT @{[ join /,/, map { $_->name } @fields }]

one of those is less readable :)

in other news, we were just in your neighborhood - had lunch at yuki.

not the best sushi in town :)
i lost your # when our wiki was updated :(

yuki smelled like fish when we entered, and some of the sushi smelled like fish. the selection was great, though.
Shoot me an email and I'll send you my number.

Weird about them smelling like fish. I haven't been in there for a while, though.
It's the multiple uses of the special variable $_ that makes it more inscrutible than it could be.
Well, something better would have been this, I think:

sub { [ @{$_[0]} => map @$_ => grep $_ => @{$_[1]} ] }

But then, I think it actually starts to look a bit clearer. Bummer.