473,385 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Re: Not fully OO ?

On 20 Sep., 18:33, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
The following definitions are AFAIK the only commonly accepted
definitions about OO:

1/ an object is defined by identity, state and behaviour
2/ objects interacts by sending messages each other
3/ an OO program is made of interacting objects

I let you find out whether Python meets these 3 definitions - and if
Java does (hint : in Python, everything you can bind to a name is an
object - this is not true in Java or C++).
This is correct but it detracts from a more general problem of
language "paradigms".

Assume you type
>>2+2
4

Now you are free to interpret this as a simple, primitive arithmetic
operation but you can also claim that 2 sends an __add__ message to 2.
Hereby the state of the 2 objects are not altered but a new 4 object
is created. OO babble is more impressive isn't it?

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.

Applying OO on interpreter level is by no means a sign of a high
quality implementation whereas structuring programs in the large will
likely benefit from class based organization and encapsulation. Of
course one can also reverse the value hierarchy and find perverse joy
in having a pure OO language but apply monkey patching everywhere. I
suppose you know which language I'm talking about...
Sep 20 '08 #1
7 1624
On Sep 20, 3:22*pm, Kay Schluehr <kay.schlu...@gmx.netwrote:
On 20 Sep., 18:33, Bruno Desthuilliers

<bdesth.quelquech...@free.quelquepart.frwrote:
The following definitions are AFAIK the only commonly accepted
definitions about OO:
1/ an object is defined by identity, state and behaviour
2/ objects interacts by sending messages each other
3/ an OO program is made of interacting objects
I let you find out whether Python meets these 3 definitions - and if
Java does (hint : in Python, everything you can bind to a name is an
object - this is not true in Java or C++).

This is correct but it detracts from a more general problem of
language "paradigms".

Assume you type
>2+2

4

Now you are free to interpret this as a simple, primitive arithmetic
operation but you can also claim that 2 sends an __add__ message to 2.
Hereby the state of the 2 objects are not altered but a new 4 object
is created. OO babble is more impressive isn't it?

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.

Applying OO on interpreter level is by no means a sign of a high
quality implementation whereas structuring programs in the large will
likely benefit from class based organization and encapsulation. Of
course one can also reverse the value hierarchy and find perverse joy
in having a pure OO language but apply monkey patching everywhere. I
suppose you know which language I'm talking about...
It sounds like you think that you -can- write OO programs in Python,
but you don't have to. I agree.
Sep 20 '08 #2
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

Sep 21 '08 #3
On Sep 20, 8:06*pm, Christian Heimes <li...@cheimes.dewrote:
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
Sep 21 '08 #4
On 20 Sep., 23:07, "Aaron \"Castironpi\" Brady" <castiro...@gmail.com>
wrote:
On Sep 20, 3:22 pm, Kay Schluehr <kay.schlu...@gmx.netwrote:
On 20 Sep., 18:33, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
The following definitions are AFAIK the only commonly accepted
definitions about OO:
1/ an object is defined by identity, state and behaviour
2/ objects interacts by sending messages each other
3/ an OO program is made of interacting objects
I let you find out whether Python meets these 3 definitions - and if
Java does (hint : in Python, everything you can bind to a name is an
object - this is not true in Java or C++).
This is correct but it detracts from a more general problem of
language "paradigms".
Assume you type
>>2+2
4
Now you are free to interpret this as a simple, primitive arithmetic
operation but you can also claim that 2 sends an __add__ message to 2.
Hereby the state of the 2 objects are not altered but a new 4 object
is created. OO babble is more impressive isn't it?
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.
Applying OO on interpreter level is by no means a sign of a high
quality implementation whereas structuring programs in the large will
likely benefit from class based organization and encapsulation. Of
course one can also reverse the value hierarchy and find perverse joy
in having a pure OO language but apply monkey patching everywhere. I
suppose you know which language I'm talking about...

It sounds like you think that you -can- write OO programs in Python,
but you don't have to. I agree.
The whole point of OO is providing high level ( system level ) not low
level ( interpreter level ) semantics. Partitioning a system into
isolated and communicating objects is a strong and important metaphor.
Recently there were some comments on the web that mentioned Erlang to
be pretty much OO in this respect although Erlang is functional and
has no base level notion of an "object". It's even well known that Joe
Armstrong holds low opinions about the entire object business.

Notice that I believe that the popular meme that OO is "bolted on"
Python has little if nothing to do with OO itself but with API
consistency. When people have to type len(x) instead of x.len() this
breaks their expectations on how the language has to behave.
Sep 21 '08 #5
Christian Heimes wrote:
Kay Schluehr wrote:
>Actually it is simply wrong in the mentioned case
[...]
>
It's not wrong. You have found a simple optimization. Lot's of compilers
for lots of languages optimize code by code folding.
I don't think he meant that Python is wrong somehow, but that the OO
babble of what happens for 2+2 is wrong. The babble said that, when the
code is executed, an __add__ message is sent to the 2 object, with
another 2 object as the parameter. That statement is incorrect: no
message is sent at all, but the result is available even before the
program starts.

FWIW, "2+2" is not a good case for OO in Smalltalk, either. In a typical
implementation, SmallInteger is not a real class, in the sense that 2 is
not a real object. Instead, it lives in a tagged pointer, i.e. it has no
identity.

Regards,
Martin
Sep 21 '08 #6
Martin v. Lwis wrote:
I don't think he meant that Python is wrong somehow, but that the OO
babble of what happens for 2+2 is wrong. The babble said that, when the
code is executed, an __add__ message is sent to the 2 object, with
another 2 object as the parameter. That statement is incorrect: no
message is sent at all, but the result is available even before the
program starts.
On the other hand, the inability to distinguish between "as if" and
"hah, I've looked under the covers" isn't necessarily a good trait for a
programmer. If he bases his mental model on concrete implementation
details of a production quality software product, he's bound to end up
with a cargo-cultish understanding of fundamental issues. If he uses it
to win arguments, people will flip his bozo bit pretty quickly.

</F>

Sep 21 '08 #7
Kay Schluehr wrote:
On 20 Sep., 23:07, "Aaron \"Castironpi\" Brady" <castiro...@gmail.com>
wrote:
>On Sep 20, 3:22 pm, Kay Schluehr <kay.schlu...@gmx.netwrote:
>>On 20 Sep., 18:33, Bruno Desthuilliers
<bdesth.quelquech...@free.quelquepart.frwrote:
The following definitions are AFAIK the only commonly accepted
definitions about OO:
1/ an object is defined by identity, state and behaviour
2/ objects interacts by sending messages each other
3/ an OO program is made of interacting objects
I let you find out whether Python meets these 3 definitions - and if
Java does (hint : in Python, everything you can bind to a name is an
object - this is not true in Java or C++).
This is correct but it detracts from a more general problem of
language "paradigms".
Assume you type
>2+2
4
Now you are free to interpret this as a simple, primitive arithmetic
operation but you can also claim that 2 sends an __add__ message to 2.
Hereby the state of the 2 objects are not altered but a new 4 object
is created. OO babble is more impressive isn't it?
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.
Applying OO on interpreter level is by no means a sign of a high
quality implementation whereas structuring programs in the large will
likely benefit from class based organization and encapsulation. Of
course one can also reverse the value hierarchy and find perverse joy
in having a pure OO language but apply monkey patching everywhere. I
suppose you know which language I'm talking about...
It sounds like you think that you -can- write OO programs in Python,
but you don't have to. I agree.

The whole point of OO is providing high level ( system level ) not low
level ( interpreter level ) semantics. Partitioning a system into
isolated and communicating objects is a strong and important metaphor.
Recently there were some comments on the web that mentioned Erlang to
be pretty much OO in this respect although Erlang is functional and
has no base level notion of an "object". It's even well known that Joe
Armstrong holds low opinions about the entire object business.

Notice that I believe that the popular meme that OO is "bolted on"
Python has little if nothing to do with OO itself but with API
consistency. When people have to type len(x) instead of x.len() this
breaks their expectations on how the language has to behave.
x.__len__()


Sep 22 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lewis | last post by:
I have "My Documents" redirected to a network share but when I go to open a project it says that the share is not fully trusted. I found this info: > The simplest (least work) in this situation...
4
by: Aashish Patil | last post by:
Hello, Is it possible to obtain the fully qualified name of a class in c#. What I am looking for is something analogous to Box.class.getName() that exists in Java. Its possible to get this by...
5
by: fc2 | last post by:
Hi I have a problem with fully qualified names. According to the C# language specification: "Every namespace and type has a fully qualified name, which uniquely identifies the namespace or...
23
by: Xah Lee | last post by:
The Concepts and Confusions of Pre-fix, In-fix, Post-fix and Fully Functional Notations Xah Lee, 2006-03-15 Let me summarize: The LISP notation, is a functional notation, and is not a...
1
by: Erland | last post by:
Hi all, As per my understanding in order to load an assembly using Assembly.Load() you have to provide fully qualified name of the assembly you are trying to load e.g. Assembly...
5
by: thisis | last post by:
Hi All, Hi All, (this is not the same topic as the my previous topic) What objects/methods/properties does VBScript offer for: Assuring/guarantee/make certain that ASP/VBSCript an ELEMENT...
30
by: Xah Lee | last post by:
The Concepts and Confusions of Prefix, Infix, Postfix and Fully Functional Notations Xah Lee, 2006-03-15 In LISP languages, they use a notation like “(+ 1 2)” to mean “1+2”....
8
by: Jack | last post by:
Hi, I have a single class XXX residing in a namspace with the same name: XXX. I can access my class in my code just fine with: XXX.XXX.MySub() '(Note: shared sub!) But I don't want to...
7
by: Tom | last post by:
By my estimate, greater than 90% of the online doco code does not work without additional coding effort. Fully working solutions are invaluable for the student. A guru's work measured in minutes...
6
by: Vince | last post by:
Hello all, I am using Visual Basic to open a saved query and then save information in the query to an array for later use. The problem is that the same query shows different results when opened...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.