News for hackers. Stuff that matters.
Re:Perl 5.26.0 released by rootusrootus on Thursday June 01, 2017 @10:55AM (#14460744)
As a long time Perl programmer myself who has been doing Python for the last three years, I have to say that it is much easier to write unintelligible Perl code than Python. Not that you cannot write some gross things in Python if you try, but the language defaults towards readability and the community strongly encourages it.

I recall a great talk a couple years ago at OSCON that Damian Conway gave about how you could essentially turn Perl into a custom language that exactly fit your needs. I walked out of there thinking "wow! That is incredibly awesome, and yet I would never consider it for a business environment." Perl is an appealing language for people who like languages. I count myself as one of those. But I cannot deny that Python makes so much more sense for teams of more than one person.

Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @10:59AM (#14460767)
The one thing that I miss in Python is true anonymous functions. Perl has them. JavaScript has them. Ruby has them. Python just has lambda functions which can only evaluate an expression.
Re:Perl 5.26.0 released by btilly on Thursday June 01, 2017 @11:11AM (#14460895)
Meh. In Python you can put a def inside of any scope you want and do anything that you want with it. The fact that it winds up with a name in that scope doesn't stop it from being anonymous everywhere else.

At that point the difference is just syntax.

Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @12:31PM (#14461763)
You're declaring the function within that scope. You can do this in other languages too. In Javascript, I can declare a function within a scope too:

  function myFunc () {
    var myFunc2 = function () {};
    return myFunc3().then(myFunc2);
  }

This isn't some Python-specific thing.

> At that point the difference is just syntax.

Isn't that the case with most things? If I said that I missed curly braces, that's "just syntax" too.

Re:Perl 5.26.0 released by seertaak on Thursday June 01, 2017 @01:49PM (#14462625)
I think the parent poster was referring to the fact that the critical thing is that a) you can define a function within the scope of another function, and b) you can return the inner function. To do this requires something called a closure, which in general involves some of the local variables being transferred to the heap.

You're right that almost all dynamic languages have this feature, but to give you two notable languages that don't: C doesn't allow defining inner functions. Pascal allows to define inner functions, but doesn't allow you to return them. C++ does allow you to define inner functions (actually functor classes) and allows you to return them, but you need to be explicit about the capturing process.

Re:Perl 5.26.0 released by btilly on Thursday June 01, 2017 @03:02PM (#14463376)
Right. Anything that you could want to do with an anonymous function, you can.

It is less frustrating for me than the fact that the scoping rules for a var in JavaScript mean that you're likely to scope to the nearest function call rather than loop. Despite having anonymous functions, doing what I would want to do with them in JavaScript is often much harder than doing it in Python.

Re:Perl 5.26.0 released by vram22 on Thursday June 01, 2017 @06:57PM (#14465692)
>You're declaring the function within that scope. You can do this in other languages too.

>This isn't some Python-specific thing.

I think btilly meant that by the ability to do in Python what he described (define a nested function and then return it), you get (almost) all the same features as anonymous functions (and specifically, more than Python's lambdas give you, because they can only contain an expression, not statements) - in response to what you said:

>Python just has lambda functions which can only evaluate an expression.

In fact, IIRC, Guido (van Rossum, Python creator) has been known to say, to people who complain about the limitations of lambda in Python, to just use nested functions. And BTW they are quite powerful so you can do a lot with them.

He (btilly) was not implying that other languages cannot have nested function declarations (if I understood his comment right).

Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @07:10PM (#14465790)
> And BTW they are quite powerful so you can do a lot with them.

I'm not saying that they aren't powerful. I'm saying that personally, I find declaring one-time-use functions in-line to be syntactically more pleasant / organized than sticking the function definition in the middle of functional code.

I'm not a newbie to Python, but after working with it for years, it's one of those things that I still wish existed. It's not necessarily a pain point or deal breaker or anything. I'm not even sure how it could work given Python's syntax.

Re:Perl 5.26.0 released by vram22 on Friday June 02, 2017 @10:11AM (#14469992)
>I find declaring one-time-use functions in-line to be syntactically more pleasant / organized than sticking the function definition in the middle of functional code.

Ok, I get what you mean now, and think you have a point there.

Re:Perl 5.26.0 released by mixmastamyk on Thursday June 01, 2017 @12:02PM (#14461456)
And better clarity---I've seen anonymous callback hell in .js, no thanks.
Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @12:32PM (#14461768)
That's not a requirement of anonymous callbacks. That's just a symptom of poor coding standards. It can happen in Python too.
Re:Perl 5.26.0 released by mixmastamyk on Thursday June 01, 2017 @02:59PM (#14463349)
And yet the two go hand in hand. Have never seen it in Python, though have never used twisted either.
Re:Perl 5.26.0 released by pyre on Friday June 02, 2017 @09:50AM (#14469839)
> And yet the two go hand in hand.

It's a tool that can be abused. Saying that the number of tools available should be limited so that they can't be abused seems counter-productive.

Re:Perl 5.26.0 released by mixmastamyk on Friday June 02, 2017 @06:17PM (#14473705)
The trend toward limiting ultimately counter-productive language flexibility is getting stronger, not weakening.

See static typing, golang, and functional languages.