Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: List of Functions Date: Mon, 28 Mar 2016 16:40:44 +0300 Organization: A noiseless patient Spider Lines: 29 Message-ID: <87twjqn2jn.fsf@elektro.pacujo.net> References: <3c44f0f8-d701-463e-bf2c-f5871c51bddf@googlegroups.com> <87bn5z1mkd.fsf@bsb.me.uk> <87mvpjx9kh.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="13040"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19K9HMVEtn0tTCxttzeS2Nv" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:/Rlp4fPsKHt6B0bRcZWTkgbm6QI= sha1:esjG9WdEaHzFuNJoxJCQMA3G+Qo= Xref: csiph.com comp.lang.python:105914 Dan Sommers : > On Mon, 28 Mar 2016 11:58:54 +0300, Marko Rauhamaa wrote: > >> As for Python, I don't feel a great need for anonymous functions. >> However, I keep running into a need for anonymous classes, or, >> rather, classless objects. Not a biggie. I just create a one-off >> inner class and instantiate it, but I do appreciate Java's syntactic >> innovation. > > And I always curse Java for having to create an inner class and a > method when all I need is a simple function. :-) > > I think it's Steven D'Aprano who keeps pointing out that you can > always name your tiny helper functions instead of using lambda: > > def some_complex_function(): > def f(x) = x + 2 > some_library_that_wants_a_callback(f) > some_library_that_wants_a_callback(lambda x: x + 2) > > Both calls to some_library_that_wants_a_callback run the same. Yes, but I've come to realize that I quite often need more than a function: I need an object with behavior. The solution is to use a "helper" class. Marko