Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Correct type for a simple "bag of attributes" namespace object Date: Mon, 04 Aug 2014 08:41:07 +0300 Organization: A noiseless patient Spider Lines: 48 Message-ID: <8738dclslo.fsf@elektro.pacujo.net> References: <7ef67ccc-3fc3-47dd-b858-09ef3b57a497@googlegroups.com> <87r40zmkhr.fsf@elektro.pacujo.net> <53dd0717$0$29973$c3e8da3$5496439d@news.astraweb.com> <70e5f2f1-661f-40f2-bb7a-76e569c4d092@googlegroups.com> <1407057464.64980.YahooMailNeo@web163806.mail.gq1.yahoo.com> <1407063072.46317.YahooMailNeo@web163803.mail.gq1.yahoo.com> <87wqaplj8h.fsf@elektro.pacujo.net> <53ded02e$0$29980$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx05.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="5907"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18x947o1yzE8cy9iPUo7cQ2" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:2JAMsVkNFQ2ou/k/b346IWRclsI= sha1:vXKnTpPMUaT5gfd5z9QWaqG1wiA= Xref: csiph.com comp.lang.python:75661 Steven D'Aprano : > Marko Rauhamaa wrote: > >> I've reached a point where I think classes are a superfluous OO concept. >> You only need objects. > > I don't know whether "superfluous" is correct, but they certainly are > *optional*. There are at least two types of object oriented programming: > class-bases, and prototype-based. And I'm talking about a third kind: object-based. It is in active (albeit limited) use in scheme: . I'm currently using the principle in a project of mine. In Java, you use anonymous classes for the same thing. In Python, you can think of the principle as one-time classes. So instead of writing: class A: def __init__(self, x, y, z): self.x = x self.d = y * y + z * z def f(self): return self.x - self.d you write: def A(x, y, z): d = y * y + z * z class Anonymous: def f(self): return x - d return Anonymous() Now, if you always did this, you would notice that classes are unnecessary clutter and would call for syntax like this: def A(x, y, z): d = y * y + z * z return object: def f(): return x - d Marko