News for hackers. Stuff that matters.
Re:Reasons Python Sucks by nicoburns on Tuesday December 18, 2018 @12:05PM (#18708192)
Indeed. My personal bugbear is lack of multiline lambdas. I use these all the freaking time in JS and it's infuriating that I can't in python.

At the end of the day it's a minor complaint of course.

Re:Reasons Python Sucks by nicolashahn on Tuesday December 18, 2018 @12:35PM (#18708536)
I think it makes more sense in a language where you have to write callbacks all the time. I consider it a feature in Python, because by using `def` you're forced to imbue the function with meaning by providing it a name. Otherwise, it's just reading through a potentially complicated function without any context of what it's supposed to be doing.
Re:Reasons Python Sucks by Too on Tuesday December 18, 2018 @01:45PM (#18709294)
All languages, including python, where you do a lot of asynchronous io require callbacks all the time. It's only recently python got await-support to deal with this. Single line lambdas is a real PITA when your not using asyncio and python maintainers have said they don't plan to change it :(
Re:Reasons Python Sucks by saagarjha on Tuesday December 18, 2018 @08:19PM (#18712222)
It also makes sense if you're trying to do any sort of functional programming.
Re:Reasons Python Sucks by xapata on Tuesday December 18, 2018 @11:29PM (#18713019)
I use Python for functional programming and I don't miss multiline lambdas. I have a large monitor, so vertical space isn't at a premium for me.
Re:Reasons Python Sucks by Zopieux on Tuesday December 18, 2018 @06:35PM (#18711605)
Though it doesn't take that much of an effort to just name your callback function and pass it as an argument. Python functions are first-class "objects" that can be passed around, use them!

I've always found Python lambdas to be uncanny, weird and error prone. It's kinda syntactic sugar for expression-only defs with counterintuitive scope rules. I would recommend just not using them and fall back to named functions. It's just one extra line and that way you get to name it, which is always a nice thing.

Re:Reasons Python Sucks by saagarjha on Tuesday December 18, 2018 @08:18PM (#18712216)
This is extremely heavyweight syntax for something I like to use as a lightweight construct. If I wanted a function, I would make something a function.
Re:Reasons Python Sucks by dontreact on Tuesday December 18, 2018 @09:30PM (#18712542)
x = lambda y: <code goes here>

def x(y): <code goes here>

What's so heavyweight? A new line and a tab?

Re:Reasons Python Sucks by lou1306 on Wednesday December 19, 2018 @05:33AM (#18714686)
IMO lambdas are useful because they reduce mental overhead by allowing the developer not to give names to trivial functions [1]. Compare these two equivalent pieces of code:

    youngest_person = min(people, key=lambda x: x.age)

    def get_age(x):
        return x.age
    youngest_person = min(people, key=get_age)
This may not seem like a huge difference, but using lambdas scales better.

[1] Incidentally, this is the same reason why I don't miss multi-line lambdas (in Python): multi-line functions are seldom trivial.

Re:Reasons Python Sucks by dontreact on Thursday December 20, 2018 @07:03PM (#18730388)
Yeah in the context of multi line functions the overhead is

A new line A tab A return

This does not sound heavyweight to me (in that context). In the context of a single line function I see the utility of lambdas.

Re:Reasons Python Sucks by jhuni on Tuesday December 18, 2018 @06:47PM (#18711696)
Guido Van Rossum and the development team didn't want the language to be functional. There is very little functional support in Python in general, besides not supporting first class functions over multiple lines.
Re:Reasons Python Sucks by dragonwriter on Tuesday December 18, 2018 @06:50PM (#18711713)
> There is very little functional support in Python in general, besides not supporting first class functions over multiple lines.

You are confusing “first-class functions” and “anonymous functions”, which are completely different things. Python functions are first-class, independent of length.

Re:Reasons Python Sucks by anamexis on Tuesday December 18, 2018 @07:29PM (#18711936)
It depends who you ask.

Some definitions of "first-class function" require that it have the same value semantics as any other first-class type, which would include a literal syntax/anonymous functions.