2 ms·
I never said that code wasn't readable at all. But it's more complicated than the lua code and not as easy to read. I've never used Lua in my life but barely
by Goladus 17y ago
I never said that code wasn't readable at all. But it's more complicated than the lua code and not as easy to read. I've never used Lua in my life but barely have to think about reading it. The questions I do have are keywords that are easy to search for in documentation. With the perl, I have to double-check and make sure there's nothing funny going on, and that is a VERY simple piece of code. If you look at another function in the same program (which I didn't use because the lua version is recursive which you could do in perl if you wanted), you'll see some non-obfuscated perl code that is a much better example of the pain of reading perl if you are not familiar with its idiosyncrasies. Not only do you have to trace through every step of each loop, you have to figure out what the double-asterisk syntax means and the bracket syntax.
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];
}
- zaphar 17y agoI still think this example is a bad one. Again only one example you cite really qualifies as hard to understand, the double asterisk syntax. Otherwise the foreach loops both do exactly what they read like. Even the .. syntax makes sense and does exactly what you would expect of that punctuation if you had to guess.
- berntb 17y agoYeah, you grabbed that just randomly... 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.
- Goladus 17y agoI already cited the source of the code: http://shootout.alioth.debian.org/ http://shootout.alioth.debian.org/ Specifically, the Perl version you find suspect can be found here: http://shootout.alioth.debian.org/u32q/benchmark.php?test=binarytrees&lang=perl&id=2 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 end
- berntb 17y agoTo recap: You 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.