Are Python’s Lambda Functions Flawed

Are Python’s Lambda Functions Flawed

ArjanCodes

1 год назад

14,347 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@NovasVilla
@NovasVilla - 24.05.2023 18:44

Lambda in JS are a lot better than in Python.

Ответить
@leftblank5315
@leftblank5315 - 24.05.2023 20:17

Python's syntax is so clean, it's beneficial to just create a function so you can actually test it. I personally avoid lambdas in python unless it's one off prototype project like cleaning data in pandas

Ответить
@90hijacked
@90hijacked - 24.05.2023 21:13

oh please, a lambda consists of a single expression, not a single line..

Ответить
@finleycooper8844
@finleycooper8844 - 24.05.2023 22:17

I like lambda functions for defining a function as a parameter to another function, so it can be passed without giving it a reference. I just think the code is a lot cleaner (unless the functions get complicated then it’s better to define the function beforehand)

Ответить
@WLockIV
@WLockIV - 24.05.2023 22:49

Can’t the lambda be typed using Callable?

Ответить
@maleldil1
@maleldil1 - 27.05.2023 22:24

It's undoubtedly a design flaw. Look at similar dynamic languages like Javascript and Ruby and how multiline lambdas make the code more expressive and reduce boilerplate. Hell, even Java's lambdas can be multiline.

Typing is not a problem, as demonstrated by other commenters. You would type the function receiving the lambda with Callable and let the type checker verify that the lambda satisfies the type.

Ответить
@TheSzybas
@TheSzybas - 28.05.2023 17:33

Yeah, lambdas in Python are strictly worse than in Java or JavaScript.
However lack of streams and not so extensive functional approach makes poor lambdas a bit less painful.

What I would love to see in Python are Java's streams and lambdas.

Ответить
@PetrSUsername
@PetrSUsername - 30.05.2023 20:50

For one the syntax is bit unreadable unless you use it often.

Ответить
@Saheryk
@Saheryk - 31.05.2023 02:20

I'd rather say that Python doesn't really need multi line lambdas, because in Python defining function and using it as an argument looks visually and work exactly the same.

Ответить
@munteanionut3993
@munteanionut3993 - 01.07.2023 01:54

but is it really a flaw? I mean.. can't you simply define what you need in another function and then pass that function as a handler in a lambda? or would that defy the purpose of a lambda? Also if number of parameters would be a problem, one could use `partial` I guess... am I right? I would really like to discuss about this.. I did not see lambdas as limited up until now, but maybe I haven t used them as much as some people else

Ответить
@abigailbruner
@abigailbruner - 23.07.2024 11:19

Lambda is offended by this... She thinks that you're telling her she's flawed...

Ответить
@ArjanCodes
@ArjanCodes - 02.08.2023 17:38

Check out my channel links for a free code diagnosis workshop or my free design guide! 🔥

Ответить