when a subclass is loaded, is super-class-side>>initialize executed?

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

when a subclass is loaded, is super-class-side>>initialize executed?

Ben Coman
Because I'm lazy to experiment this instant (not wanting to get distracted from my current track), and also its probably a useful remainder for others I'll just ask...

When MyClass is loaded, #initialize is sent to it.  Typically the class-side>>initialize should not call "super initialize" to avoid re-initializing the superclaass, but what if MyClass doesn't implement #initialize?  Does the message fall through to the superclass, or is #initialize only sent if MyClass implements it?

Concrete example...
FFIExternalEnumeration subclass MyEnumeration needs to be sent #initializeEnumeration when it is loaded.  We have...

    FFIExternalEnustmeration>>#initialize 
self initializeEnumeration

so is MyEnumeration *required* to implement its own MyEnumeration>>#initialize, or can it rely FFIExternalEnustmeration>>#initialize.   I believe it is the former, but just wanted to confirm my understanding.

cheers -ben


Reply | Threaded
Open this post in threaded view
|

Re: when a subclass is loaded, is super-class-side>>initialize executed?

Guillermo Polito
Class side #initialize is executed only when a class is loaded for the first time.
Posteriors "updates" to the class, or even to the initialize method do not re-execute #initialize.

Now, about the FFI particular requirements, I'd let Esteban answer :)

On Tue, Nov 14, 2017 at 3:08 AM, Ben Coman <[hidden email]> wrote:
Because I'm lazy to experiment this instant (not wanting to get distracted from my current track), and also its probably a useful remainder for others I'll just ask...

When MyClass is loaded, #initialize is sent to it.  Typically the class-side>>initialize should not call "super initialize" to avoid re-initializing the superclaass, but what if MyClass doesn't implement #initialize?  Does the message fall through to the superclass, or is #initialize only sent if MyClass implements it?

Concrete example...
FFIExternalEnumeration subclass MyEnumeration needs to be sent #initializeEnumeration when it is loaded.  We have...

    FFIExternalEnustmeration>>#initialize 
self initializeEnumeration

so is MyEnumeration *required* to implement its own MyEnumeration>>#initialize, or can it rely FFIExternalEnustmeration>>#initialize.   I believe it is the former, but just wanted to confirm my understanding.

cheers -ben





--

   

Guille Polito

Research Engineer

Centre de Recherche en Informatique, Signal et Automatique de Lille

CRIStAL - UMR 9189

French National Center for Scientific Research - http://www.cnrs.fr


Web: http://guillep.github.io

Phone: +33 06 52 70 66 13

Reply | Threaded
Open this post in threaded view
|

Re: when a subclass is loaded, is super-class-side>>initialize executed?

Pavel Krivanek-3
In reply to this post by Ben Coman
Hi,

the #initialize message is sent only to the classes that implement this method. In *.st files it is an explicit call, Monticello does it slightly smarter way, see MCMethodDefinition>>#postloadOver:

Cheers,
-- Pavel

2017-11-14 3:08 GMT+01:00 Ben Coman <[hidden email]>:
Because I'm lazy to experiment this instant (not wanting to get distracted from my current track), and also its probably a useful remainder for others I'll just ask...

When MyClass is loaded, #initialize is sent to it.  Typically the class-side>>initialize should not call "super initialize" to avoid re-initializing the superclaass, but what if MyClass doesn't implement #initialize?  Does the message fall through to the superclass, or is #initialize only sent if MyClass implements it?

Concrete example...
FFIExternalEnumeration subclass MyEnumeration needs to be sent #initializeEnumeration when it is loaded.  We have...

    FFIExternalEnustmeration>>#initialize 
self initializeEnumeration

so is MyEnumeration *required* to implement its own MyEnumeration>>#initialize, or can it rely FFIExternalEnustmeration>>#initialize.   I believe it is the former, but just wanted to confirm my understanding.

cheers -ben



Reply | Threaded
Open this post in threaded view
|

Re: when a subclass is loaded, is super-class-side>>initialize executed?

Sven Van Caekenberghe-2


> On 14 Nov 2017, at 09:40, Pavel Krivanek <[hidden email]> wrote:
>
> Hi,
>
> the #initialize message is sent only to the classes that implement this method. In *.st files it is an explicit call, Monticello does it slightly smarter way, see MCMethodDefinition>>#postloadOver:

Note: the actual source code has to be different. I sometimes put a 'last changed' date tag in a comment to force execution.

> Cheers,
> -- Pavel
>
> 2017-11-14 3:08 GMT+01:00 Ben Coman <[hidden email]>:
> Because I'm lazy to experiment this instant (not wanting to get distracted from my current track), and also its probably a useful remainder for others I'll just ask...
>
> When MyClass is loaded, #initialize is sent to it.  Typically the class-side>>initialize should not call "super initialize" to avoid re-initializing the superclaass, but what if MyClass doesn't implement #initialize?  Does the message fall through to the superclass, or is #initialize only sent if MyClass implements it?
>
> Concrete example...
> FFIExternalEnumeration subclass MyEnumeration needs to be sent #initializeEnumeration when it is loaded.  We have...
>
>     FFIExternalEnustmeration>>#initialize
> self initializeEnumeration
>
> so is MyEnumeration *required* to implement its own MyEnumeration>>#initialize, or can it rely FFIExternalEnustmeration>>#initialize.   I believe it is the former, but just wanted to confirm my understanding.
>
> cheers -ben
>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: when a subclass is loaded, is super-class-side>>initialize executed?

Ben Coman
In reply to this post by Pavel Krivanek-3
Thx. Thats exactly what I was looking for. The key part being "self isInitializer" where...
    isInitializer
        ^ selector = #initialize and: [classIsMeta]

Now I also see "self isExternalStructureFieldDefinition"
    "Postloading of FFI fields. This code will be called when loading FFI structures that are not by default in the image."

Could something similar be done like "self isEnumDecl" ?  It would be a minor improvement to not have write up in blog posts that 
MyFFIExternalEnumeration needs a class-side #initialize simply to do "self initializeEnumeration" 
when having #enumDecl is a strong convention and indicator that intialization is required.

Or is that starting to load up with too many implicit initializations?

Alternatively, what consideration has been given to pragmas for class initialization?
For example this seems more self contained and explicit....
    MyFFIExternalEnumeration class >> enumDecl
        <classInitialization: #initializeEnumeration>
        ^ #( EnumA  1   EnumB 2)

cheers -ben

On 14 November 2017 at 16:40, Pavel Krivanek <[hidden email]> wrote:
Hi,

the #initialize message is sent only to the classes that implement this method. In *.st files it is an explicit call, Monticello does it slightly smarter way, see MCMethodDefinition>>#postloadOver:

Cheers,
-- Pavel

2017-11-14 3:08 GMT+01:00 Ben Coman <[hidden email]>:
Because I'm lazy to experiment this instant (not wanting to get distracted from my current track), and also its probably a useful remainder for others I'll just ask...

When MyClass is loaded, #initialize is sent to it.  Typically the class-side>>initialize should not call "super initialize" to avoid re-initializing the superclaass, but what if MyClass doesn't implement #initialize?  Does the message fall through to the superclass, or is #initialize only sent if MyClass implements it?

Concrete example...
FFIExternalEnumeration subclass MyEnumeration needs to be sent #initializeEnumeration when it is loaded.  We have...

    FFIExternalEnustmeration>>#initialize 
self initializeEnumeration

so is MyEnumeration *required* to implement its own MyEnumeration>>#initialize, or can it rely FFIExternalEnustmeration>>#initialize.   I believe it is the former, but just wanted to confirm my understanding.

cheers -ben