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.
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.
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.
>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).
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.
Ok, I get what you mean now, and think you have a point there.
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.
See static typing, golang, and functional languages.
At that point the difference is just syntax.