From: Aahz on
In article <vIaVn.238$vD2.10(a)news-server.bigpond.net.au>,
Neil Hodgson <nyamatongwe+thunder(a)gmail.com> wrote:
>WANG Cong:
>>
>> 4) Also, this will _somewhat_ violate the OOP princples, in OOP,
>> this is and should be implemented by inherence.
>
> Most object oriented programming languages starting with Smalltalk
>have allowed adding attributes (addInstVarName) to classes at runtime.
>Low level OOPLs like C++ and Delphi did not implement this for
>efficiency reasons.

That reminds me of this quote:

"...some experts might say a C++ program is not object-oriented without
inheritance and virtual functions. As one of the early Smalltalk
implementors myself, I can say they are full of themselves." --zconcept
--
Aahz (aahz(a)pythoncraft.com) <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it." --Dijkstra
From: Bruno Desthuilliers on
Aahz a �crit :
> In article <4c2747c1$0$4545$426a74cc(a)news.free.fr>,
> Bruno Desthuilliers <bdesth.quelquechose(a)free.quelquepart.fr> wrote:
>> Python has no pretention at "elegance".
>
> That's not true at all. More precisely, I would agree with you if the
> emphasis is on "pretention" but not if the emphasis is on elegance;

Python Zen, #9 (or #8 if you're a TrueHacker !-))
From: Bruno Desthuilliers on
Carl Banks a �crit :
> On Jun 27, 3:49 am, Bruno Desthuilliers
> <bdesth.quelquech...(a)free.quelquepart.fr> wrote:
>> WANG Cong a �crit :
>>
>>> On 06/26/10 00:11, Neil Hodgson <nyamatongwe+thun...(a)gmail.com> wrote:
>>>> WANG Cong:
>>>>> 4) Also, this will _somewhat_ violate the OOP princples, in OOP,
>>>>> this is and should be implemented by inherence.
>>>> Most object oriented programming languages starting with Smalltalk
>>>> have allowed adding attributes (addInstVarName) to classes at runtime.
>>> Thanks, I have to admit that I know nothing about Smalltalk.
>> Then you really don't know much about OO.
>
> I don't really know much about Smalltalk either.
>

Duh. I cancelled this totally stupid and useless post a couple seconds
after hitting the send button, but still too late :(

So first let me present my apologies to WANG Cong and everyone else,
this was a crude, arrogant and totally stupid thing to say, and I should
know better. Sorry.

Now on why I first wrote this (warning : personal opinions ahead):

"object" started with Simula, but objects in Simula are mostly glorified
ADTs with type-based "polymorphic" dispatch. Smalltalk (and all it's
environment) got _way_ further by turning this into a coherent whole by
introducing messages (which are more than just type-based polymorphic
dispatch - Smalltalk's messages are objects themselves) and "code
blocks" - as the only mean to control "flow". I believe that Smalltalk
is (so far) the only "OO" language that was innovative enough to really
escape from good old procedural programming, and as such possibly the
only "True" OOPL.

Now for various reasons (including implementation issues and
conservatism), it happened that the Simula approach to OO became the
mainstream with languages like C++ then Java, and that most of "OO"
litterature - "OOP principles", golden rules etc - is about this somehow
very restricted approach, so people being taught "OO" that way have a
very restricted - and incomplete - vision of what OO is really about.
That was how I was taught OO, and I always felt that there was something
wrong, inconsistant or missing.

Studying Smalltalk (however briefly) was for me a real "AHA",
mind-opening moment - suddenly OO made sense as this coherent,
comprehensive and innovative approach to programming I so far failed to
find in Java or C++.

Now I don't mean one has to master Smalltalk to be allowed to talk about
OO, nor that OO can't exist outside Smalltak (Python being IMHO another
exemple of an interesting and mostly coherent object system, even if
doesn't go as far as Smalltalk do), but - pardon me if this seems
arrogant (and please correct me if it really is) - I can't help thinking
that one cannot really understand OO whithout at least a brief study of
Smalltalk (and - once again - a full Smalltalk environment, as Smalltalk
the language is only one part of the 'full' object system).

Hope this will at least help those I may have offended understand my
point, however stupidly I expressed it :(

B.
From: Bruno Desthuilliers on
Alexander Kapps a écrit :
(snip)
> While I personally don't agree with this proposal (but I understand why
> some people might want it), I can see a reason.
>
> When disallowing direct attribute creation, those typos that seem to
> catch newcommers won't happen anymore. What I mean is this:
>
> class Foo(object):
> def __init__(self):
> self.somearg = 0
>
> f = Foo()
> f.soemarg = 42
>
> ---^ There, typo, but still working
>
> It's something like a custom __setattr__ that errors out when trying to
> assign to an attribute that doesn't exists,

Chicken and egg problem, really : f.__dict__['somearg'] doesn't exists
until "self.somearg = 0" is executed.

The "problem" is that Python's methods are only thin wrapper around
functions (cf http://wiki.python.org/moin/FromFunctionToMethod) so
there's no difference between "self.somearg = 0" in Foo.__init__ and
"f.somearg = 42".

IOW, there's no way to implement this proposal without completely
changing Python's object model.
From: Aahz on
In article <4c285e7c$0$17371$426a74cc(a)news.free.fr>,
Bruno Desthuilliers <bruno.42.desthuilliers(a)websiteburo.invalid> wrote:
>Aahz a �crit :
>> In article <4c2747c1$0$4545$426a74cc(a)news.free.fr>,
>> Bruno Desthuilliers <bdesth.quelquechose(a)free.quelquepart.fr> wrote:
>>>
>>> Python has no pretention at "elegance".
>>
>> That's not true at all. More precisely, I would agree with you if the
>> emphasis is on "pretention" but not if the emphasis is on elegance;
>
>Python Zen, #9 (or #8 if you're a TrueHacker !-))

....and this implies that Python has no focus on elegance because...?
--
Aahz (aahz(a)pythoncraft.com) <*> http://www.pythoncraft.com/

"If you don't know what your program is supposed to do, you'd better not
start writing it." --Dijkstra