super initialize is not a good idea for Behaviors ; )

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

super initialize is not a good idea for Behaviors ; )

Mariano Martinez Peck
Hi folks. After a couple of hours of trying to find a problem, I finally come to the cause:  using super initialize is not always good.
When I implement #initialize, I ALWAYS do "super initialize" in the first line of such method. Today, I found a problem while doing this in class side #initialize.

I have a particular class and I did:

MyClass class >> initialize
super initialize.
"My own specific code to run"

But when sending MyClass initialize, I discovered that the "super initialize" did something I wasnt aware:

Behavior >> initialize
    "moved here from the class side's #new"
    super initialize.
    superclass := Object.
    "no longer sending any messages, some of them crash the VM"
    methodDict := self emptyMethodDictionary.
    format := Object format


in my case MyClass has subclass from ProtoObject, not Object. And of course, I got an empy method dictionary...etc.

So...I just wanted to share my problem to avoid other's one.

Cheers

Mariano


Reply | Threaded
Open this post in threaded view
|

Re: super initialize is not a good idea for Behaviors ; )

Ramon Leon-5
On 12/13/2010 03:28 PM, Mariano Martinez Peck wrote:
> Hi folks. After a couple of hours of trying to find a problem, I finally
> come to the cause:  using super initialize is not always good.
> When I implement #initialize, I ALWAYS do "super initialize" in the
> first line of such method. Today, I found a problem while doing this in
> class side #initialize.

You should only super init on the instance side, not the class side;
pretty sure this is a well known issue.

--
Ramon Leon
http://onsmalltalk.com

Reply | Threaded
Open this post in threaded view
|

Re: super initialize is not a good idea for Behaviors ; )

Mariano Martinez Peck


On Mon, Dec 13, 2010 at 11:33 PM, Ramon Leon <[hidden email]> wrote:
On 12/13/2010 03:28 PM, Mariano Martinez Peck wrote:
Hi folks. After a couple of hours of trying to find a problem, I finally
come to the cause:  using super initialize is not always good.
When I implement #initialize, I ALWAYS do "super initialize" in the
first line of such method. Today, I found a problem while doing this in
class side #initialize.

You should only super init on the instance side, not the class side; pretty sure this is a well known issue.

heheheh I leart it today, in the "hard way"  ;)
thanks ramon


--
Ramon Leon
http://onsmalltalk.com


Reply | Threaded
Open this post in threaded view
|

Re: super initialize is not a good idea for Behaviors ; )

Schwab,Wilhelm K
It has certainly been well-known to be potentially disastrous in Dolphin.



________________________________________
From: [hidden email] [[hidden email]] On Behalf Of Mariano Martinez Peck [[hidden email]]
Sent: Monday, December 13, 2010 5:35 PM
To: [hidden email]
Subject: Re: [Pharo-project] super initialize is not a good idea for Behaviors ; )

On Mon, Dec 13, 2010 at 11:33 PM, Ramon Leon <[hidden email]<mailto:[hidden email]>> wrote:
On 12/13/2010 03:28 PM, Mariano Martinez Peck wrote:
Hi folks. After a couple of hours of trying to find a problem, I finally
come to the cause:  using super initialize is not always good.
When I implement #initialize, I ALWAYS do "super initialize" in the
first line of such method. Today, I found a problem while doing this in
class side #initialize.

You should only super init on the instance side, not the class side; pretty sure this is a well known issue.

heheheh I leart it today, in the "hard way"  ;)
thanks ramon


--
Ramon Leon
http://onsmalltalk.com