News for hackers. Stuff that matters.
Re:Go + Services = One Goliath Project by im3w1l on Saturday December 21, 2019 @07:00PM (#21854114)
If you need more power than a lambda you would use a nested function, e.g.

    def a(n):
      def b():
        print(n)
      return b
Re:Go + Services = One Goliath Project by WoodTree on Saturday December 21, 2019 @07:14PM (#21854193)
Nesting functions like this can have a bad performance impact because functions in Python are objects. Normally, all of those function objects are instantiated once when you load the module. However nested functions will be instantiated at runtime every time their parent is called, even if they aren’t used. This cost is perceptible in hot paths.
Re:Go + Services = One Goliath Project by krallja on Saturday December 21, 2019 @09:03PM (#21854652)
A lambda also behaves this way; it’s how it captures the closure scope.
Re:Go + Services = One Goliath Project by edflsafoiewq on Saturday December 21, 2019 @07:35PM (#21854292)
Are lambdas different?
Re:Go + Services = One Goliath Project by baron816 on Saturday December 21, 2019 @08:26PM (#21854508)
I’ve never seen it create a bottle neck, have you?
Re:Go + Services = One Goliath Project by weyland108 on Saturday December 21, 2019 @08:46PM (#21854588)
It will definitely be a problem if you use JIT interpreter like pypy
Re:Go + Services = One Goliath Project by saagarjha on Saturday December 21, 2019 @07:03PM (#21854137)
That's a lot of boilerplate for a closure…
Re:Go + Services = One Goliath Project by mlyle on Saturday December 21, 2019 @07:10PM (#21854178)
The trivial lambda case is short, and you can do what the parent said if you want to do something that doesn't fit into the trivial lambda case well.
Re:Go + Services = One Goliath Project by saagarjha on Saturday December 21, 2019 @07:13PM (#21854191)
The "lambda" keyword isn't :(
Re:Go + Services = One Goliath Project by ptx on Saturday December 21, 2019 @07:31PM (#21854269)
Where's the boilerplate? "def b():" and "() => {}" are both 8 characters.

It is annoying that you have to give the function a name, though.

Re:Go + Services = One Goliath Project by aserafini on Saturday December 21, 2019 @07:55PM (#21854382)
On the one hand it’s annoying, on the other it enforces a discipline of thought in the same way that having to name variables does.
Re:Go + Services = One Goliath Project by baddox on Saturday December 21, 2019 @08:16PM (#21854458)
That’s an interesting principle, something like “a block of code that is complex enough to be written across multiple lines of code ought to be given a name,” but standard idiomatic Python already violates that principle by featuring multiple lines in the body of a for loop. The fact that the body of a for loop can be multiple lines but the “body” of a lambda cannot is an arbitrary syntax inconsistency.
Re:Go + Services = One Goliath Project by jcheng on Saturday December 21, 2019 @07:57PM (#21854389)

    def b(x):
      return x + 1
vs

    x => x + 1
Re:Go + Services = One Goliath Project by earenndil on Saturday December 21, 2019 @07:06PM (#21854156)

    def a(n):
        return lambda: print(n)
Re:Go + Services = One Goliath Project by saagarjha on Saturday December 21, 2019 @07:10PM (#21854179)
That's a couple characters over most languages I normally use. Plus lambdas have a number of strange warts and restrictions (no multi-line lambdas?) that leave me feeling that Python really dislikes traditional functional programming constructs.
Re:Go + Services = One Goliath Project by WoodTree on Saturday December 21, 2019 @07:27PM (#21854258)
Python has become less functional over time. It’s also not a particularly good OO language either. It’s really a more descriptive sort of bash that became ubiquitous despite its short comings.