4 ms·
seriously? You have to know perl's control flow ("unless" unless is that difficult to understand? Its plain english has totally understandable semantics wit
by zaphar 17y ago
seriously?
You have to know perl's control flow ("unless"
unless is that difficult to understand? Its plain english has totally understandable semantics without reading a lick of documentation about perl.
you have to know perl references(->)
This is just like C++ and an arrow is pretty dang readable and plain to me. Perhaps even more informative than a period.
you have to know perl's variable prefixes.
I might be convinced to give you this one but really reading the perl code isn't that difficult even with 3 extra symbols to know. Even not knowing the symbols the code example you show is both readable and concise.
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 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.
- Goladus 17y agoI 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