Not fully OO ?

Aaron "Castironpi" Brady castironpi at gmail.com
Sun Sep 21 04:11:22 CEST 2008


On Sep 20, 8:06 pm, Christian Heimes <li... at cheimes.de> wrote:
> Kay Schluehr wrote:
> > Actually it is simply wrong in the mentioned case and here is the
> > proof:
>
> > def foo():
> >     return 2+2
>
> > import dis
> > dis.dis(foo)
>
> >   2           0 LOAD_CONST               2 (4)
> >               3 RETURN_VALUE
>
> > OO is a heuristic method used to understand the semantics of a
> > programming language. It can also inspire language design but as
> > you've rightly said: jugde yourself and see how far you get with it.
>
> It's not wrong.

The meaning of the Python program is, internally, on a cycle-by-cycle
basis, "Object 2; send add( Object 2 ) to Object 2; Return object 4."

CPython doesn't do this, but due to the fact that there are no cases
in which that distinction affects the output, it's still an
implementation of Python.

Or at least, a practical implementation.

> You have found a simple optimization. Lot's of compilers
> for lots of languages optimize code by code folding.
>
> Python's peephole optimizer replaces code like 2+2 with 4.
>
> Christian




More information about the Python-list mailing list