Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Building CPython Date: Sat, 16 May 2015 11:08:25 +0300 Organization: A noiseless patient Spider Lines: 61 Message-ID: <87egmhrll2.fsf@elektro.pacujo.net> References: <7JN4x.37133$Q41.15375@fx25.am4> <6w35x.645690$I97.19867@fx31.am4> <874mnfunpn.fsf@elektro.pacujo.net> <87bnhmgqrx.fsf@elektro.pacujo.net> <87twvdsbom.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="18492"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184lqqMPL2aY4GNN0VKciWn" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:TGGKIWa8+/lsg3cya0MzfrQ8z8A= sha1:sK0qi1I6dsCXyOrlKgZY8YNtqS8= Xref: csiph.com comp.lang.python:90726 BartC : > I suppose in many cases an object will have no attributes of its own, > and so it can rapidly bypass the first lookup. Almost all objects have quite many instance attributes. That's what tells objects apart. > I don't understand the need for an object creation (to represent A.B > so that it can call it?) but perhaps such an object can already exist, > prepared ready for use. Note that almost identical semantics could be achieved without a class. Thus, these two constructs are almost identical: class C: def __init__(self, x): self.x = x def square(self): return self.x * self.x def cube(self): return self.x * self.square() ## class O: pass def C(x): o = O() def square(): return x * x def cube(): return x * square() o.square = square o.cube = cube return o IOW, the class is a virtually superfluous concept in Python. Python has gotten it probably without much thought (other languages at the time had it). I comes with advantages and disadvantages: + improves readability + makes objects slightly smaller + makes object instantiation slightly faster - goes against the grain of ducktyping - makes method calls slower - makes method call semantics a bit tricky Marko