News for hackers. Stuff that matters.
Re:Writing a DSL with Python by rw on Sunday September 06, 2009 @07:18PM (#808285)
If you give something a name, yet still only use it once, what's the point? It is just semantic clutter to do that (unless, of course, you can't use multiline lambdas...).
Re:Writing a DSL with Python by CaptSolo on Sunday September 06, 2009 @09:38PM (#808430)
There is no big harm in giving something a name. Giving a name also helps if you find a need to reuse it later. Plus a name can give a hint to what this code is for.
Re:Writing a DSL with Python by rw on Sunday September 06, 2009 @09:56PM (#808449)
Yet, if you look in functional programming code (e.g. Haskell, Scheme), you'll find many anonymous lambdas (that in python would be > 1 line). Why would good coders bother doing that?
Re:Writing a DSL with Python by eru on Monday September 07, 2009 @07:11AM (#808954)
If something is small and enough to be anonymous, it's usually simply enough to be expressed without binding a variable.

(See point-free style.)

Re:Writing a DSL with Python by rw on Monday September 07, 2009 @09:44AM (#809125)
Obviously. Show us how to do point-free style in Python. We're talking about Python's lame implementation of anonymous functions, not something that it doesn't have any implementation of.
Re:Writing a DSL with Python by eru on Monday September 07, 2009 @04:02PM (#809667)
Oh, I thought you were talking about programmers' habits in Haskell.
Re:Writing a DSL with Python by GeneralMaximus on Sunday September 06, 2009 @10:41PM (#808486)
In Python, you can easily define methods within methods, so there is little semantic clutter at the toplevel.

  def doSomething():
    def doSomethingElse():
      # Code goes here.
      pass
    
    eggs = filter(doSomethingElse, spam)
    for cheese in eggs:
      # Do something.
      pass