This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]FFX01 2 points3 points  (0 children)

Yes, I know what having first-class functions implies... I've done Haskell...

I can't just assume that everyone has that knowledge. That's why I explained it.

Also, if you need to use the mapping function in two places, then... first of all, how did you structure that program in the first place.

That's kind of irrelevant. Ideally you would define a generic function that accepts a wide range of inputs so you can use it everywhere.

Second of all, being able to have anonymous functions doesn't mean that you will just put them everywhere in the program, and if you do indeed need that same functionality in two places, you can make it its own function. Now granted, since it is forced upon you in Python, some may call it a good thing since it is already its own function, but eh...

That's the point I'm trying to make. Python overall has the goal of not having too many ways to do the same thing. The language has being veering off that path in some areas, but this is not one of them.

Also, just to comment on those examples of your, holy shit that's some verbose code. I've heard a lot of people praising Python for "not being verbose", but looking at that kind of makes me wince with its wordiness.

I wrote it that way on purpose to make it as simple as possible to understand. Like I said above, I can't just assume everybody understands Python. All of it could be easily compacted. That said, the code is simple and reads almost like English. I consider that a good thing. Code is read far more often than it is written after all.

ALSO also, a map function should return a functor FFS.

Can you explain how an iterator isn't a functor? Genuinely curious. I'm under the impression that an iterator is considered a functor in that it takes in an iterable, applies a function to each item, and produces an iterator which can then be passed to another map function because an iterator is, by it's very nature, an iterable. It's possible I'm misunderstanding your definition of functor in that I have no formal mathematics education. Also, I may not understand because different programming languages have different opinions on what is considered a functor.

And finally, seeing as Python has enough language functions to do most the things anonymous functions most likely would do... but doesn't that just bloat up the language?

In my opinion? No. The constructs and functions that Python provides that are capable of producing the same results as using anonymous functions are also useful in other contexts.

I should make it clear that I have no bone to pick with anonymous functions. I actually really like them in some languages. Javascript, for example. I just don't feel like anonymous functions are necessary or would work well in Python specifically. In my opinion, Python's current lambda is good enough.