all i could think of is "stop writing python". it seems to me that a lot of these problems are fundamental problems with python. i continue to not understand why anybody likes python the language. the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical: let test1 = fun x -> x * x let test2 x = x * x both re…
Stop writing lambda expressions in Python
41–50 of 202 posts
Re: Stop writing lambda expressions in Python
#42all i could think of is "stop writing python". it seems to me that a lot of these problems are fundamental problems with python. i continue to not understand why anybody likes python the language. the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical: let test1 = fun x -> x * x let test2 x = x * x both re…
Nobody really likes Python the language especially much, but lots of people love Python the ecosystem, because it lets them get stuff done. I can think of a dozen languages I like better than Python, but none that's more practical in as many different contexts. -------------------- Edit: Apparently, there are some people who do like Python the language, and some people who dislike Python the ecosystem. If you want to…
Re: Stop writing lambda expressions in Python
#43all i could think of is "stop writing python". it seems to me that a lot of these problems are fundamental problems with python. i continue to not understand why anybody likes python the language. the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical: let test1 = fun x -> x * x let test2 x = x * x both re…
Yep. Had a coworker like that recently. Loved “simple” code, chock full of mutable data everywhere, where everything was written out a good 3 or 4 times longer than I would have liked to see it.
I call that sort of “simple, explicit” (repetitive) code “My Summer Vacation” code, after a bit in an old Cheech and Chong skit where the highschool kids have to read their essays to the class.
Re: Stop writing lambda expressions in Python
#44 def length_and_alphabetical(string):
"""Return sort key: length first, then case-normalized string."""
return (len(string), string.casefold())
You just said the same thing three different ways. Not having to do that is exactly what lambda expressions are for.Re: Stop writing lambda expressions in Python
#45Earlier quoted context omitted.
I'm not sure what you mean by the first half of your comment. Both def and lambda create functions, and quoting from the article "Lambda expressions are just a special syntax for making functions. They can only have one statement in them and they return the result of that statement automatically.". def binds it to a name at the same time, which is remembered in the object (which AFAIK isn't really used for anything e…
it's because i am not that deeply familiar with python and the article is not clear itself on this. what is he complaining about then if they are identical in what's returned? is it simply because the REPL returns instead of the function name? why does the REPL do this? are they different in some subtle way? the point was in something like f#, lambda creates a function which can then be bound to a name if you want. i…
Re: Stop writing lambda expressions in Python
#46Anonymous functions are vital to any modern high level language.
I think most people get hung up on the word. If the keyword was changed from “lambda” to “fun” for example I think it wouldn’t be as obtuse to more intermediate developers.
To be honest I think the lambda does Python a service vs a disservice. It helps to illustrate that everything in Python is an object. Once you realize you can treat functions similarly to how you treat things like integers and strings your mind opens up to functional style. Assigning a function to a variable the same way you do with a string, for instance, helps to reinforce this concept.
Re: Stop writing lambda expressions in Python
#47all i could think of is "stop writing python". it seems to me that a lot of these problems are fundamental problems with python. i continue to not understand why anybody likes python the language. the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical: let test1 = fun x -> x * x let test2 x = x * x both re…
> i read an interview with hal abelson where he called python's lambda broken Can you give a link? I'd be interested to read it.
Re: Stop writing lambda expressions in Python
#48all i could think of is "stop writing python". it seems to me that a lot of these problems are fundamental problems with python. i continue to not understand why anybody likes python the language. the fact that creating a function with lambda versus the normal way is different is bonkers. for example, in f# (and other sane languages), the following are identical: let test1 = fun x -> x * x let test2 x = x * x both re…
> i read an interview with hal abelson where he called python's lambda broken Can you give a link? I'd be interested to read it.
http://www.gigamonkeys.com/code-quarterly/2011/hal-abelson/
the paragraph he says it in is:
> It’s just a different course. We could have done it in Scheme and I sort of wish we had. And for random reasons we didn’t. But the thing that ties it together—if you had fifteen seconds to describe the whole course—it’s still about abstraction and modularity. The beginning of that course is not very different from the beginning of 6.001 other than you do it in Python. But at that point, where you’re not building interpreters yet, you can pretty much do this stuff in Python. You have to contend with Python’s broken notion of lambda but other than that it’s not really that different.
he mentions it as an aside really, but the overall interview itself is very good. abelson is a treat to listen to.
Re: Stop writing lambda expressions in Python
#49A good rule of thumb is given by the google python coding guidelines [1]:
"Okay to use them for one-liners. If the code inside the lambda function is any longer than 60-80 chars, it's probably better to define it as a regular (nested) function."
[1] https://github.com/google/styleguide/blob/gh-pages/pyguide.m...
Re: Stop writing lambda expressions in Python
#50 colors = ["Goldenrod", "Purple", "Salmon", "Turquoise", "Cyan"]
normalized_colors = map(str.casefold, colors)