Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nope - just a style thing. You don't need lambdas either - named functions are just as powerful.

It depends on what you define as power, and how wide of a continuum you are willing to presume that it runs.

Named functions add two levels of clutter.

The first is to the actual code, because you have to add a name to something that never wanted one, and it has to be defined apart from where it is used. You could give it a fluff name, but that is worse than no name at all. The reader is left wondering what the function is for, which requires carrying unnecessary mental baggage. It would seem more powerful to me that you just define a function where it is used, and not worry about having to carry around that extra mental information for later on; the less state you need to keep the better. But I may only say that because I, like you, tend to think functionally.

The second is to the namespace, because now there is a symbol in the environment that doesn't need to be there. It's not a huge deal, but it is just another bit of extraneous fluff.

Anyway, not meaning to turn this into a language war. Just a couple of thoughts that popped into my head when I read your first paragraph.



I agree with this big time. I hate increasing the "vocabulary" of my program unnecessarily.


The "correct" alternative to multiline lambda might be not a named function but an explicit code block: no clutter at the prize of vertical space.

  result = []  
  for item in iterable:
      # here goes multiline lambda as an explicit suite
      # that computes value
      result.append(value)




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

Search: