an oop question

Alan Gauld learn2program at gmail.com
Thu Nov 3 06:43:28 EDT 2022


On 03/11/2022 00:25, Julieta Shem wrote:

>> |OOP to me means only messaging, local retention and protection and
>> |hiding of state-process, and extreme late-binding of all things.
> 
> I'm wondering how Python fails to satisfy his definition.

Python doesn't do any form of data protection/hiding. All
attributes are public by default.

In Smalltalk all attributes are private, with no way to
make them public... Actually in C++/Java terms I believe
they are "protected" because subclasses can access
them(I think?).

Also Python is not a purely OOP language, in that you can write
functional and procedural code in Python if you wish. In
Smalltalk thats notionally impossible because everything
is an object. And all programming statements are messages
to objects.

Even an if/else test is a message to the boolean object:

(5>3) ifTrue: <block of code>
      ifFalse: <block of code>

ifTrue is a message to the boolean result of the expression
which has a parameter of a block of code. It executes the
block if the boolean is true.
ifFalse is likewise a message to the same boolean object
but only executes its block if the boolean is false.

(Apologies if the syntax is out, its been a while since I
wrote any Smalltalk!)

Similarly loops are implemented as messages:

<boolean> whileTrue: <block>
<Number> to: <Number> do: <block>

So in Smalltalk absolutely everything is a message to an object.

Python by comparison is much more traditional in form.

It is possible to write procedural, non OOP code in
Smalltalk but you really have to fight the system to
do so.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Python-list mailing list