News for hackers. Stuff that matters.
Re:Stop writing lambda expressions in Python by andrewstuart on Thursday September 27, 2018 @06:12PM (#18089259)
Private functions do not restrict the usage of that function to one point in the code. There's a world of difference between a coding convention - essentially a comment to say "please don't access this function from outside the current class" versus it simply being impossible to do so. And the "private" convention does not say "don't use this function at any other point except one", it says "please don't access this function from outside the current class", which is completely different to the point I make. Anonymous inline functions reduce lines of code and complexity.

>>because it does not want to promote that style.

Why would Python not want to promote a more readable, simple, powerful, reliable and maintainable programming style?

Can you reference anything to back this assertion?

Re:Stop writing lambda expressions in Python by anentropic on Friday September 28, 2018 @04:41PM (#18096879)
The parent comment about private naming convention is a red herring.

99% of the time in places where you might use a multi-line anonymous function you're already inside another function

So when you define your named function in Python, it is only available within the scope of the current method call and there's no danger of it being abused by other developers.

The lack of true private vars in python is a separate issue, and one of the best things about the language (because library authors inevitably get carried away and mark things as private which don't need to be - then you're stuck in copy & paste land... I did loads of ActionScript back in the day and this was super frustrating)

Re:Stop writing lambda expressions in Python by joshuamorton on Thursday September 27, 2018 @08:29PM (#18090057)
As a user of JavaScript and es6, fat arrows are only necessary if you haven't started using async and await syntax, and I found myself almost never using fat arrows after moving to async/await.

Indeed naming my functions resulted in more testable and clearer code.

Re:Stop writing lambda expressions in Python by andrewstuart on Thursday September 27, 2018 @09:10PM (#18090243)
Hmmmm. I don't see the relationship between async/await and fat arrows.

Can you explain more about how async/await obviates the need for fat arrows?

Re:Stop writing lambda expressions in Python by joshuamorton on Thursday September 27, 2018 @09:18PM (#18090279)
Just async is callback based.

You don't need callbacks with async/await. No callbacks, no need for fat arrow.

Re:Stop writing lambda expressions in Python by andrewstuart on Friday September 28, 2018 @01:03AM (#18091215)
Interesting idea.
Re:Stop writing lambda expressions in Python by danShumway on Friday September 28, 2018 @02:09PM (#18095598)
Getting rid of fat arrows is one thing, but I use async/await pretty much all the time, and I still use anonymous functions in my code.

  await (async function () {
    //Do a thing
  }());
I don't think async changes anything about how useful or problematic an anonymous function is.
Re:Stop writing lambda expressions in Python by joshuamorton on Friday September 28, 2018 @02:45PM (#18095920)
That feels like a weird pattern (for one because you can have async fat arrows), but also because in general I find

    await request_some_data()
much clearer than

    await (async () => {
        // just make the async request inline
    })()
Re:Stop writing lambda expressions in Python by danShumway on Friday September 28, 2018 @03:15PM (#18096206)
When arrow functions were first released, they didn't support the `async` keyword. I guess that wasn't fixed until ES2018? Maybe earlier - I think Babel would compile them pretty early on. Regardless, some people who adopted async patterns early got into the habit of avoiding arrow functions entirely, so it wouldn't be crazy to me to hear someone say, "I used arrow functions before I learned async."

Otherwise, this is just restating the same arguments people already made above.

There's no practical reason why

  (() => {
  
  }());

would be useful but

  await (async () => {
  
  }());
wouldn't be. The scenario you're talking about where async code removes the need to have an anonymous function only makes sense if you were only using anonymous functions for callbacks. In practice, that's not the only (or even primary) use case for people who advocate inlining code in Javascript. They're specifically advising against the pattern where single-use functions are given names and removed from program flow.
Re:Stop writing lambda expressions in Python by joshuamorton on Friday September 28, 2018 @03:21PM (#18096250)
Correct, and I fundamentally disagree with that pattern. If it's more than a single expression, it's doing something complex enough to deserve a name or to be mocked in tests, etc.
Re:Stop writing lambda expressions in Python by dragonwriter on Friday September 28, 2018 @10:07AM (#18093452)
While I can see async/await replacing a lot of the most common use in JS, anonymous functions have a lot more uses than that (passing a single use function to generic algorithm, like an ordering function to a sorting routine, is one of the more common other uses, across languages.)
Re:Stop writing lambda expressions in Python by another-cuppa on Friday September 28, 2018 @02:08AM (#18091386)
Come on. You've defined a function inside another function. It's very clear that you've done it so you can pass it to some higher level function. If someone comes along and starts using your inner function willy nilly in the outer function without anyone noticing then you've got much bigger problems that multiline lambdas are not going to help you with.