Re: OOP / language design question

2006-04-27 Thread bruno at modulix
Lawrence D'Oliveiro wrote: > In article <[EMAIL PROTECTED]>, > "Carl Banks" <[EMAIL PROTECTED]> wrote: > > >>bruno at modulix wrote: >> >>>[EMAIL PROTECTED] wrote: >>> I was wondering, why you always have to remember to call bases' constructors >>> >>> >>>s/constructors/__init__/ >>> >>>

Re: OOP / language design question

2006-04-27 Thread Carl Banks
Lawrence D'Oliveiro wrote: > In article <[EMAIL PROTECTED]>, > "Carl Banks" <[EMAIL PROTECTED]> wrote: > > >bruno at modulix wrote: > >> [EMAIL PROTECTED] wrote: > >> > I was wondering, why you always have to remember to call bases' > >> > constructors > >> > >> > >> s/constructors/__init__/ > >

Re: OOP / language design question

2006-04-27 Thread Duncan Booth
Lawrence D'Oliveiro wrote: >>In other words, the object is constructed in Python before any >>__init__ is called, but in C++ it isn't constructed until after all >>the base class constructors have returned. > > But if "construction" is what a constructor does, then you're wrong. > I may be wrong

Re: OOP / language design question

2006-04-27 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>, "Carl Banks" <[EMAIL PROTECTED]> wrote: >bruno at modulix wrote: >> [EMAIL PROTECTED] wrote: >> > I was wondering, why you always have to remember to call bases' >> > constructors >> >> >> s/constructors/__init__/ >> >> the __init__() method is *not* the construct

Re: OOP / language design question

2006-04-27 Thread Lawrence D'Oliveiro
In article <[EMAIL PROTECTED]>, Duncan Booth <[EMAIL PROTECTED]> wrote: >Carl Banks wrote: > >> You know, Python's __init__ has almost the same semantics as C++ >> constructors (they both initialize something that's already been >> allocated in memory, and neither can return a substitute object).

Re: OOP / language design question

2006-04-26 Thread bruno at modulix
Brian van den Broek wrote: > Bruno Desthuilliers said unto the world upon 25/04/06 06:52 PM: > >> Duncan Booth a écrit : >> (snip) >>> Apart from the fact that you can delete the method 'dothis' from both >>> classes with no effect on the code? >> >> Mmmm... Oh, I see. Agreed, this is not a very g

Re: OOP / language design question

2006-04-26 Thread Brian van den Broek
Bruno Desthuilliers said unto the world upon 25/04/06 06:52 PM: > Duncan Booth a écrit : > >>bruno at modulix wrote: >> >> >> >>>class Base(object): >>> def __init__(self, arg1): >>> self.attr1 = arg1 >>> self.dothis() >>> >>> def dothis(self): >>> return self.attr1 >>> >>>class Derived(Base

Re: OOP / language design question

2006-04-26 Thread bruno at modulix
Duncan Booth wrote: > bruno at modulix wrote: > > >>It's *already* split : __new__ construct the object, __init__ >>initialize it. >> >>>That's why I would go for the 2-phase construction: >> >>But that's already what you have. > > Very good point. > > >>>after the first phase >>>you have an

Re: OOP / language design question

2006-04-26 Thread Duncan Booth
bruno at modulix wrote: > It's *already* split : __new__ construct the object, __init__ > initialize it. > >> That's why I would go for the 2-phase construction: > > But that's already what you have. Very good point. >> after the first phase >> you have an object which is fully initialised,

Re: OOP / language design question

2006-04-26 Thread Carl Banks
Duncan Booth wrote: > Alex Martelli wrote: > > >> What I think I'm trying to get at is that I believe that most > >> situations where someone actually tries to do something in the base > >> initialiser which requires calling a virtual method are probably also > >> cases where the initialiser is do

Re: OOP / language design question

2006-04-26 Thread bruno at modulix
Duncan Booth wrote: > Alex Martelli wrote: > > >>>What I think I'm trying to get at is that I believe that most >>>situations where someone actually tries to do something in the base >>>initialiser which requires calling a virtual method are probably also >>>cases where the initialiser is doing t

Re: OOP / language design question

2006-04-26 Thread Duncan Booth
Alex Martelli wrote: >> What I think I'm trying to get at is that I believe that most >> situations where someone actually tries to do something in the base >> initialiser which requires calling a virtual method are probably also >> cases where the initialiser is doing too much: i.e. separating th

Re: OOP / language design question

2006-04-25 Thread Alex Martelli
Duncan Booth <[EMAIL PROTECTED]> wrote: ... > Actually, this is quite an interesting example becaue it wouldn't work in > C++: if you tried the same trick the call to dothis from the base > constructor (even assuming it is virtual) would actually call Base.dothis. Yep. > I think you have demo

Re: OOP / language design question

2006-04-25 Thread Bruno Desthuilliers
Duncan Booth a écrit : > bruno at modulix wrote: > > >>class Base(object): >> def __init__(self, arg1): >>self.attr1 = arg1 >>self.dothis() >> >> def dothis(self): >>return self.attr1 >> >>class Derived(Base): >> def __init__(self, arg1, arg2=0): >>self.attr2 = arg2 >>Base.

Re: OOP / language design question

2006-04-25 Thread Duncan Booth
bruno at modulix wrote: > class Base(object): > def __init__(self, arg1): > self.attr1 = arg1 > self.dothis() > > def dothis(self): > return self.attr1 > > class Derived(Base): > def __init__(self, arg1, arg2=0): > self.attr2 = arg2 > Base.__init__(self, arg1) > > de

Re: OOP / language design question

2006-04-25 Thread bruno at modulix
Duncan Booth wrote: > bruno at modulix wrote: > > >>Duncan Booth wrote: >>(snip) >> >>>Usually though, if a subclass doesn't immediately call the base class >>>constructors as the first thing it does in __init__ it indicates poor >>>code and should be refactored. >> >>Not necessarily. It's a comm

Re: OOP / language design question

2006-04-25 Thread Carl Banks
Duncan Booth wrote: > In other words, the object is constructed in Python before any __init__ is > called, but in C++ it isn't constructed until after all the base class > constructors have returned. That's true. Good point. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list

Re: OOP / language design question

2006-04-25 Thread Duncan Booth
Carl Banks wrote: > You know, Python's __init__ has almost the same semantics as C++ > constructors (they both initialize something that's already been > allocated in memory, and neither can return a substitute object). There is a significant difference: imagine B is a base type and C a subclas

Re: OOP / language design question

2006-04-25 Thread Carl Banks
bruno at modulix wrote: > [EMAIL PROTECTED] wrote: > > I was wondering, why you always have to remember to call bases' > > constructors > > > s/constructors/__init__/ > > the __init__() method is *not* the constructor. Object's instanciation > is a two-stage process: __new__() is called first, t

Re: OOP / language design question

2006-04-25 Thread Duncan Booth
bruno at modulix wrote: > Duncan Booth wrote: > (snip) >> Usually though, if a subclass doesn't immediately call the base class >> constructors as the first thing it does in __init__ it indicates poor >> code and should be refactored. > > Not necessarily. It's a common case to have some computati

Re: OOP / language design question

2006-04-25 Thread Carl Banks
[EMAIL PROTECTED] wrote: > Heiko Wundram wrote: > > Because sometimes you don't want to call the base classes constructors? > Sounds strange to me at the moment, but I'll try to adjust to this > thought. In Java and C++, classes have private members that can only be accessed by the class itself (a

Re: OOP / language design question

2006-04-25 Thread bruno at modulix
[EMAIL PROTECTED] wrote: > I was wondering, why you always have to remember to call bases' > constructors s/constructors/__init__/ the __init__() method is *not* the constructor. Object's instanciation is a two-stage process: __new__() is called first, then __init__(). -- bruno desthuillier

Re: OOP / language design question

2006-04-25 Thread bruno at modulix
Duncan Booth wrote: (snip) > Usually though, if a subclass doesn't immediately call the base class > constructors as the first thing it does in __init__ it indicates poor code > and should be refactored. Not necessarily. It's a common case to have some computations to do/some attributes to set i

Re: OOP / language design question

2006-04-25 Thread Duncan Booth
[EMAIL PROTECTED] wrote: > Heiko Wundram wrote: >> Because sometimes you don't want to call the base classes constructors? > Sounds strange to me at the moment, but I'll try to adjust to this > thought. It makes sense in more static languages such as C++. The base class is initialised by the con

Re: OOP / language design question

2006-04-25 Thread Diez B. Roggisch
> Well, I can imagine it's done to make sure that the base(s) are > properly constructed. Sound s sensible to me. It often is - there are popular examples in python where missing a constructor will cause a program to fail spectacular. But is it _always_ a sensible thing to do? No. If you only want

Re: OOP / language design question

2006-04-25 Thread Rene Pijlman
[EMAIL PROTECTED]: >I think I'll need some shift in thinking after C++. +1 qotw -- René Pijlman -- http://mail.python.org/mailman/listinfo/python-list

Re: OOP / language design question

2006-04-25 Thread cctv . star
Heiko Wundram wrote: > Because sometimes you don't want to call the base classes constructors? Sounds strange to me at the moment, but I'll try to adjust to this thought. > Python zen says: "Better explicit than implicit," and in this case it hits > the nail on the head. Better to see right away

Re: OOP / language design question

2006-04-25 Thread cctv . star
Diez B. Roggisch wrote: > I have another question for you: why does JAVA enforce that a constructor of > a base-class must be called prior to everything else in the derived class's > constructor? Well, I can imagine it's done to make sure that the base(s) are properly constructed. Sound s sensible

Re: OOP / language design question

2006-04-25 Thread Diez B. Roggisch
[EMAIL PROTECTED] wrote: > I was wondering, why you always have to remember to call bases' > constructors explicitly from the derived class constructor? Why hasn't > this been enforced by the language? I have another question for you: why does JAVA enforce that a constructor of a base-class must

Re: OOP / language design question

2006-04-25 Thread Heiko Wundram
Am Dienstag 25 April 2006 12:34 schrieb [EMAIL PROTECTED]: > I was wondering, why you always have to remember to call bases' > constructors explicitly from the derived class constructor? Why hasn't > this been enforced by the language? Because sometimes you don't want to call the base classes cons

Re: OOP / language design question

2006-04-25 Thread Rene Pijlman
[EMAIL PROTECTED]: >I was wondering, why you always have to remember to call bases' >constructors explicitly from the derived class constructor? Why hasn't >this been enforced by the language? Probably because the language doesn't know whether the subclass wants to override its base class's constr

OOP / language design question

2006-04-25 Thread cctv . star
I was wondering, why you always have to remember to call bases' constructors explicitly from the derived class constructor? Why hasn't this been enforced by the language? -- http://mail.python.org/mailman/listinfo/python-list