Live data from Hacker News

Why is perl losing its touch?

google.com

71–73 of 73 posts

Re: Why is perl losing its touch?

#71
post #47

Earlier quoted context omitted.

Python is often claimed not to have closures but that isn't really true, what it doesn't have is anonymous functions. It does have a lambda statement, but that is limited to a single statement. So what you end up writing is more akin to: def multiplier_maker(a): def temp(b): return b * a return temp That is because Python allows you to declare a function anyware, even inside other functions.

And if you want to emulate static variables in a function, you can do that: def counter(): counter.x += 1 return counter.x counter.x = 0 counter() > 1 counter() > 2 Beware! singleton variables, mutable state, etc.

You can do it by closing over a variable as well. Python closes over things just fine, it just has problems rebinding variables in outer scopes that aren't the global one. Here, I just make the variable a container, so I can alter a value inside it, instead of rebinding it ( only python2 has this problem, python3 has a "nonlocal" keyword to work around this in the language )

    >>> def counter():
    ...   x = [ 1 ]
    ...   def count():
    ...     y = x[ 0 ]
    ...     x[ 0 ] += 1
    ...     return y
    ...   return count
    ... 
    >>> count = counter()
    >>> count()
    1
    >>> count()
    2
    >>> count()
    3
    >>> count()
    4
    >>> 
    >>> otherCount = counter()
    >>> otherCount()
    1
    >>> otherCount()
    2
    >>> count()
    5
    >>> count()
    6
    >>> otherCount()
    3
    >>>

Re: Why is perl losing its touch?

#72

I think it's better to flip the question around: I make my living writing single-page web apps in JavaScript. These days, everything I do, even on the server, is in JavaScript. What does Perl do a hundred times better than the latest in the JavaScript universe (ES6, Meteor, node.js, etc.)? If it doesn't, that right there is your answer.

> What does Perl do a hundred times better than the latest in the JavaScript universe (ES6, Meteor, node.js, etc.)? A concise POSIX interface. Conciseness in general, really. How many node one-liners do you see?

The fact that I can be contemplating career suicide after reading the source to CGI.pm one minute (once amazingly useful and best of breed, now a crufty monster) and the next doing insanely useful things with metaprogramming, declarative interfaces and terse, easy to read code :)

Re: Why is perl losing its touch?

#73
post #21

Earlier quoted context omitted.

I have to agree. There's nothing you need Perl for, and nothing it specifically offers. Like if you want to do something in Wordpress you can only use PHP, no choice. If you want to code a Linux driver you have to use C. If you want nice features like awesome readability you choose Python. If you want awesome power you use some kind of Lisp or Haskell. There is not a single (well known) reason for using Perl. Even if…

No language handles regular expressions as easily as Perl. Perl's power has always been in its power to do text processing. That said, it's objects and pointers are a joke. At least Perl 5's are. As for Perl 6, I don't know. It couldn't hold my attention for 15 years.

You missed qr/Moo(?:se)?/

All the nice bits of dynamic OO with the option to go procedural or functional when needed.

Post reply on HN