sub bottom_up_tree {
my($depth) = @_;
my @pool;
push @pool, [undef, undef, -$_] foreach 0..2**$depth-1;
foreach my $exponent (reverse(0..($depth-1))) {
push @pool, [reverse(splice(@pool, 0, 2)), $_]
foreach reverse(-(2**$exponent-1) .. 0);
}
return $pool[0];
}I've never seen code in any language doing that kind of things to an array -- without lots of comments.
Strange that you didn't publish the equivalent Lua code here...? So you aren't trolling? :-)
Edit: Removed reasoned argument. Waste on what must be a troll.
Edit: Also. Double asterisk and square braces goes straight back to ol' C. You are a troll.
Specifically, the Perl version you find suspect can be found here: http://shootout.alioth.debian.org/u32q/benchmark.php?test=bi...
And it really was mostly random. I picked lua because I knew some people who used it, and was pretty sure it was a somewhat similar language to Perl in terms of problems its designed to solve, but that I'd never seen it before. I picked binary trees mostly because I was pretty sure both languages would have results for that test.
I wanted to see if it would be easier or harder to read the Lua vs. the Perl. It was easier for me to understand the Lua than the Perl, and I have attempted to explain that.
I don't care if you believe me or not. To anyone who doesn't already program in Perl full time: go to that site and pick random samples of code to read. Read through the various different solutions. Decide for yourself which language is most annoying to deal with.
For the record, here is the lua version of the same function.
local function BottomUpTree(item, depth)
if depth > 0 then
local i = item + item
depth = depth - 1
local left, right = BottomUpTree(i-1, depth), BottomUpTree(i, depth)
return { item, left, right }
else
return { item } -- Faster for LuaJIT: return { item, false }
end
endYou wrote the same old point -- the expressibility and some old ugliness make it a bit steeper learning curve for Perl. A troll favorite. You wrote that Perl was one of your two most experienced languages -- but obviously, you're a beginner not doing many hours development/month.
Everyone pointed out the standard answers -- this is a small cost in the beginning, learning libraries dwarf this, Perl is easy to use for people knowing C/sh/etc, there are plus/minus with expressibility, etc.
Then your second code example is on the wrong side of obfuscation with modifying an array while appending to it -- inside two tight loops!.
(Sure, this was some performance test and it was the language's worst case, or something, so it had been rewritten in an attempt to get better speed, but... still, I've seen saner things in obfuscation code.)
When this is pointed out, you just claim that it is an accident that you happened to pick this hairy recursive-to-iterative example...
I would have given you the benefit of the doubt, if this hadn't been a typical troll subject... But, no.
b) This was the third trolled Perl discussion I read on HN in a row. And trolled in the same boring way. Why would I want to waste more time on language wars?!
Yes perl may have some quirks but for the most part it "Does exactly what you think it would by reading it". That was a design goal of the language after all.
Of course anyone could write perl code that is incomprehensible and makes use of perls semantics to obfuscate their purpose (using every example you cite) but that is with effort on their part and significant effort in some cases. And just to drive the point home may I present lua code that is way harder to read than any perl code I've ever seen even in an obfuscated perl contest: http://www.corsix.org/content/obfuscated-lua
To reiterate, no one in their right mind would right lua code like that except as an exercize and experiment. Same thing goes for perl. The perl code you show above is perfectly readable. Unless does exactly what you expect it to. -> arrows mean exactly what you would expect them to. Arrays start at 0 exactly like most programmers expect them to. and on top of that its readable. The only point you bring up that I think supports you argument is the @_ and argument passing semantics. But again that's only one and as another poster pointed out Lua has at least one also in it's array indexing.