Not fully OO ?

Christian Heimes lists at cheimes.de
Sun Sep 21 03:06:40 CEST 2008


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. 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