Hacker News new | ask | show | jobs
by smabie 2170 days ago
lambda's take up too much space and are really ugly. They're visual noise and serve no purpose. Besides, the name 'lambda' is bad, and intuitive. There's a reason why no new languages have chosen 'lambda' for anonymous functions. Python:

map, filter, zip, etc should produce concrete values, not iterators. It's annoying to constantly turn iterators into lists. Like if scala's map or fold took in a list and produced an iterator, that would be super annoying. There's no point. If you want an iterator, turn the collection into an iterator. There's no reason for a function to take a list and return an iterator, unless that function is 'toIter.'

Ugly python:

    list(map(lambda x: 2*x, [1, 2, 3, 4]))
Julia:

   map(x -> 2*x, [1, 2, 3, 4])
Or even better Julia:

   2*.[1, 2, 3, 4]
I dunno, it's like Python tries its best to make code super verbose and ugly. I just don't understand why it is the way it is. It doesn't make sense.
1 comments

> There's a reason why no new languages have chosen 'lambda' for anonymous functions.

Beware of people who say "there's a reason" and then don't say what that reason is.

I suspect the reason in this case is that languages which use C-ish syntax it would make no senes to have lambda as a keyword. Python doesn't use C-ish syntax, so that reason doesn't apply.

> It's annoying to constantly turn iterators into lists.

So don't. Why are you constantly turning iterators into lists?

> There's no reason for a function to take a list and return an iterator,

Here are 5 reasons:

1. There are many cases where the iterator will never be evaluated, meaning you save O(n) time.

2. Even in cases where you evaluate the iterator, you'll often have performed many transformations upon that iterator. Forcing 5 transformations all at once means you have 1 loop instead of 5, meaning again you save O(n) time.

3. It encourages writing functional code, which doesn't depend on order of execution. (This is why Simon Peyton Jones says Haskell has lazy evaluation: it keeps them honest about side effects).

4. Explicit is better than implicit. Guessing that a user will want a list is a reasonable guess, but you're doing a lot of work based on that guess, and some percentage of the time you'll be wrong. It's better to do the minimum work necessary and let the user explicitly determine what type of result they want.

5. Consistent extensibility: map, zip, etc. take lots of iterable types. You could attempt to return the same iterable type as you receive, but then there isn't an easy way for users to use zip on user-defined types. It's better to call the type's __iter__ function and then just use that, as this allows users to define higher-order functions on their own types.

Look, functors (and therefore monads as well) are closed under fmap. That should be the end of the story.
It's pretty bizarre to assert that structures made up by some mathematician in a void should be the basis of a programming language intended to solve real-world problems, especially in response to giving real-world reasons for why it is the way it is.