Hacker News new | past | comments | ask | show | jobs | submit login

Personally, I use them often and disagree with a lot of this sentiment. I also disagree with a significant portion of PEP8, however.

Anonymous 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.

Van Rossum started to work on Python in 1989 and released the first version in 1991. Python is modern in the sense of being still very well alive but it's deeply rooted in the 80s, and it shows with all those double underscore __magic functions__, the self argument in methods (the way we were doing object oriented programming in C, without the ++) and others.

Compared to JavaScript it didn't evolve it's syntax much. Of course JS was much worse off to start with.

`self` is about being explicit with parameters. Rust does the same thing and that's a more "modern" language.

The `__magic__` is about avoiding naming conflicts while still being explicit. It's a choice between magic or reserving a lot of names.

Or use normal method names chosen by the class author like for example Ruby and many other languages. In the case of the standard library it's easy to be consistent. I concede that in any other case it can be hard or impossible.

About self, it's so strange to define a method with 2 arguments and call it with only one. Not only it's strange, it feels the opposite of being explicit. Most other languages manage to do without that self (Java, Ruby).

I run into another oddity today. Yesterday if forgot about

    a = 0
    if not a:
        print("like in C")

Rust also has the issue of having three kinds of self, and those differences matter.

> Anonymous functions are vital to any modern high level language.

I don’t think you’re wrong, but I am also not experienced enough to know why this would be the case. What is the virtue of having an anonymous function? I get that it makes code somewhat easier to read and write if you’re only using the function once and it’s short, but that seems like an edge case. What am I missing?

First class functions are vital. Not so sure that anonymity is vital.

I don't know an easy answer to this, but I recommend reading SICP: https://mitpress.mit.edu/sites/default/files/sicp/index.html

The expression inside a {list,dictionary,etc} comprehension is semantically the same as an anonymous function.

This is a great question with many great answers. The process of discovering those answers will illuminate huge swaths of the computer science landscape beyond the tiny, relatively insignificant patch that people call "programming."

You are about to embark on a great adventure. I wish you luck on your quest!

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact