News for hackers. Stuff that matters.
Re:Perl Myths Talk 2009 by zaphar on Friday September 25, 2009 @05:31PM (#844450)
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

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.

Re:Perl Myths Talk 2009 by Goladus on Friday September 25, 2009 @06:58PM (#844625)
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];
    }
Re:Perl Myths Talk 2009 by zaphar on Friday September 25, 2009 @07:24PM (#844681)
I 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.
Re:Perl Myths Talk 2009 by berntb on Friday September 25, 2009 @07:26PM (#844684)
Yeah, 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.

Re:Perl Myths Talk 2009 by Goladus on Sunday September 27, 2009 @11:54AM (#846941)
I already cited the source of the code: 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=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
Re:Perl Myths Talk 2009 by berntb on Monday September 28, 2009 @07:15AM (#848197)
To 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.

Re:Perl Myths Talk 2009 by Goladus on Tuesday September 29, 2009 @01:46PM (#850892)
And yet you refuse to discuss this with me in private, where you cannot accuse me of trolling.
Re:Perl Myths Talk 2009 by berntb on Tuesday September 29, 2009 @06:56PM (#851528)
a) You didn't touch my description above. Enough.

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?!