Package extension. Adding instance variables to classes

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

Package extension. Adding instance variables to classes

Pharo Smalltalk Users mailing list
Hi,

I am working on a package named ClassNamesAnalyzer and I need to add code to third party classes in other packages (for instance the FAMIX-Core package).
“Extending” third party classes with methods is easy; I just need to categorise my methods under the *ClassNamesAnalyzer protocole so that loading my package will load them in the image.
However, if I want to add instance variables to theses classes, they are not there when I load the package in a new image.

So my question is : is there a way to include instance variables addition to other packages in my package?
Another question is : is it good practice to add instance variables to classes in third party packages and is there a way to avoid it (because I am not very confortable with that idea)?

Thanks in advance,
Abdelghani
Reply | Threaded
Open this post in threaded view
|

Re: Package extension. Adding instance variables to classes

Pavel Krivanek-3


2018-05-07 12:25 GMT+02:00 Alidra Abdelghani via Pharo-users <[hidden email]>:


---------- Přeposlaná zpráva ----------
From: Alidra Abdelghani <[hidden email]>
To: [hidden email]
Cc: 
Bcc: 
Date: Mon, 7 May 2018 11:25:49 +0100
Subject: Package extension. Adding instance variables to classes
Hi,

I am working on a package named ClassNamesAnalyzer and I need to add code to third party classes in other packages (for instance the FAMIX-Core package).
“Extending” third party classes with methods is easy; I just need to categorise my methods under the *ClassNamesAnalyzer protocole so that loading my package will load them in the image.
However, if I want to add instance variables to theses classes, they are not there when I load the package in a new image.

So my question is : is there a way to include instance variables addition to other packages in my package?

Currently not, you should use privateState
 
Another question is : is it good practice to add instance variables to classes in third party packages and is there a way to avoid it (because I am not very confortable with that idea)?

It is not, see FAMIXContainerEntity>>#definedAnnotationTypes how this issue is currently being solved using the privateState. 

Cheers,
-- Pavel
 

Thanks in advance,
Abdelghani


Reply | Threaded
Open this post in threaded view
|

Re: Package extension. Adding instance variables to classes

Pharo Smalltalk Users mailing list
In reply to this post by Pharo Smalltalk Users mailing list
Hi Pavel,

Thank you for your answer.
I actually didn’t know about this mechanism. 
I think it is will do the job :)
 I have probably to rewrite some parts pf my code to access my variables through privateState.  no?


Thanks again
Abdelghani
On 07 May 2018, at 13:15, [hidden email] wrote:


Message: 1
Date: Mon, 7 May 2018 13:43:56 +0200
From: Pavel Krivanek <[hidden email]>
To: Any question about pharo is welcome <[hidden email]>
Subject: Re: [Pharo-users] Package extension. Adding instance
variables to classes
Message-ID:
<[hidden email]>
Content-Type: text/plain; charset="utf-8"

2018-05-07 12:25 GMT+02:00 Alidra Abdelghani via Pharo-users <
[hidden email]>:



---------- P?eposlan? zpr?va ----------
From: Alidra Abdelghani <[hidden email]>
To: [hidden email]
Cc:
Bcc:
Date: Mon, 7 May 2018 11:25:49 +0100
Subject: Package extension. Adding instance variables to classes
Hi,

I am working on a package named ClassNamesAnalyzer and I need to add code
to third party classes in other packages (for instance the FAMIX-Core
package).
?Extending? third party classes with methods is easy; I just need to
categorise my methods under the *ClassNamesAnalyzer protocole so that
loading my package will load them in the image.
However, if I want to add instance variables to theses classes, they are
not there when I load the package in a new image.

*So my question is* : is there a way to include instance variables
addition to other packages in my package?


Currently not, you should use privateState


*Another question is* : is it good practice to add instance variables to
classes in third party packages and is there a way to avoid it (because I
am not very confortable with that idea)?


It is not, see FAMIXContainerEntity>>#definedAnnotationTypes how this issue
is currently being solved using the privateState.

Cheers,
-- Pavel



Thanks in advance,
Abdelghani


Reply | Threaded
Open this post in threaded view
|

Re: Package extension. Adding instance variables to classes

Guillermo Polito
Just be careful, that privateState thing looks like a Moose only Famix feature. It't not available in plain Pharo objects :)

On Wed, May 9, 2018 at 2:09 AM, Alidra Abdelghani via Pharo-users <[hidden email]> wrote:


---------- Forwarded message ----------
From: Alidra Abdelghani <[hidden email]>
To: Pavel Krivanek <[hidden email]>
Cc: Any question about pharo is welcome <[hidden email]>
Bcc: 
Date: Wed, 9 May 2018 01:09:06 +0100
Subject: Re: Package extension. Adding instance variables to classes
Hi Pavel,

Thank you for your answer.
I actually didn’t know about this mechanism. 
I think it is will do the job :)
 I have probably to rewrite some parts pf my code to access my variables through privateState.  no?


Thanks again
Abdelghani
On 07 May 2018, at 13:15, [hidden email] wrote:


Message: 1
Date: Mon, 7 May 2018 13:43:56 +0200
From: Pavel Krivanek <[hidden email]>
To: Any question about pharo is welcome <[hidden email]>
Subject: Re: [Pharo-users] Package extension. Adding instance
variables to classes
Message-ID:
<[hidden email]>
Content-Type: text/plain; charset="utf-8"

2018-05-07 12:25 GMT+02:00 Alidra Abdelghani via Pharo-users <
[hidden email]>:



---------- P?eposlan? zpr?va ----------
From: Alidra Abdelghani <[hidden email]>
To: [hidden email]
Cc:
Bcc:
Date: Mon, 7 May 2018 11:25:49 +0100
Subject: Package extension. Adding instance variables to classes
Hi,

I am working on a package named ClassNamesAnalyzer and I need to add code
to third party classes in other packages (for instance the FAMIX-Core
package).
?Extending? third party classes with methods is easy; I just need to
categorise my methods under the *ClassNamesAnalyzer protocole so that
loading my package will load them in the image.
However, if I want to add instance variables to theses classes, they are
not there when I load the package in a new image.

*So my question is* : is there a way to include instance variables
addition to other packages in my package?


Currently not, you should use privateState


*Another question is* : is it good practice to add instance variables to
classes in third party packages and is there a way to avoid it (because I
am not very confortable with that idea)?


It is not, see FAMIXContainerEntity>>#definedAnnotationTypes how this issue
is currently being solved using the privateState.

Cheers,
-- Pavel



Thanks in advance,
Abdelghani






--

   

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: Package extension. Adding instance variables to classes

Pharo Smalltalk Users mailing list
Ok, got it.

Thanks Guille

Abdelghani
On 10 May 2018, at 21:59, Guillermo Polito <[hidden email]> wrote:

Just be careful, that privateState thing looks like a Moose only Famix feature. It't not available in plain Pharo objects :)

On Wed, May 9, 2018 at 2:09 AM, Alidra Abdelghani via Pharo-users <[hidden email]> wrote:


---------- Forwarded message ----------
From: Alidra Abdelghani <[hidden email]>
To: Pavel Krivanek <[hidden email]>
Cc: Any question about pharo is welcome <[hidden email]>
Bcc: 
Date: Wed, 9 May 2018 01:09:06 +0100
Subject: Re: Package extension. Adding instance variables to classes
Hi Pavel,

Thank you for your answer.
I actually didn’t know about this mechanism. 
I think it is will do the job :)
 I have probably to rewrite some parts pf my code to access my variables through privateState.  no?


Thanks again
Abdelghani
On 07 May 2018, at 13:15, [hidden email] wrote:


Message: 1
Date: Mon, 7 May 2018 13:43:56 +0200
From: Pavel Krivanek <[hidden email]>
To: Any question about pharo is welcome <[hidden email]>
Subject: Re: [Pharo-users] Package extension. Adding instance
variables to classes
Message-ID:
<[hidden email]>
Content-Type: text/plain; charset="utf-8"

2018-05-07 12:25 GMT+02:00 Alidra Abdelghani via Pharo-users <
[hidden email]>:



---------- P?eposlan? zpr?va ----------
From: Alidra Abdelghani <[hidden email]>
To: [hidden email]
Cc:
Bcc:
Date: Mon, 7 May 2018 11:25:49 +0100
Subject: Package extension. Adding instance variables to classes
Hi,

I am working on a package named ClassNamesAnalyzer and I need to add code
to third party classes in other packages (for instance the FAMIX-Core
package).
?Extending? third party classes with methods is easy; I just need to
categorise my methods under the *ClassNamesAnalyzer protocole so that
loading my package will load them in the image.
However, if I want to add instance variables to theses classes, they are
not there when I load the package in a new image.

*So my question is* : is there a way to include instance variables
addition to other packages in my package?


Currently not, you should use privateState


*Another question is* : is it good practice to add instance variables to
classes in third party packages and is there a way to avoid it (because I
am not very confortable with that idea)?


It is not, see FAMIXContainerEntity>>#definedAnnotationTypes how this issue
is currently being solved using the privateState.

Cheers,
-- Pavel



Thanks in advance,
Abdelghani






--
   
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

Phone: +33 06 52 70 66 13

Dr. Abdelghani Alidra 
Enseignant-chercheur
Université 20 août 1955
SKIKDA-ALGÉRIE 
Mob:+ 213 550 453 391

Reply | Threaded
Open this post in threaded view
|

Re: Package extension. Adding instance variables to classes

Herby Vojčík
In reply to this post by Guillermo Polito


Guillermo Polito wrote:
> Just be careful, that privateState thing looks like a Moose only Famix
> feature. It't not available in plain Pharo objects :)

In ES6 mailing list, they had this problem re how to do private state
for objects, and it was shown that having private state is sort of
isomorphic to having WeakMap indexed by objects. So in case of Pharo,
I'd say using WeakIdentitityKeyDictionary can do the trick. Without
resorting to any external dependency.

Herby

> On Wed, May 9, 2018 at 2:09 AM, Alidra Abdelghani via Pharo-users
> <[hidden email] <mailto:[hidden email]>> wrote:
>
>
>
>     ---------- Forwarded message ----------
>     From: Alidra Abdelghani <[hidden email]
>     <mailto:[hidden email]>>
>     To: Pavel Krivanek <[hidden email]
>     <mailto:[hidden email]>>
>     Cc: Any question about pharo is welcome <[hidden email]
>     <mailto:[hidden email]>>
>     Bcc:
>     Date: Wed, 9 May 2018 01:09:06 +0100
>     Subject: Re: Package extension. Adding instance variables to classes
>     Hi Pavel,
>
>     Thank you for your answer.
>     I actually didn’t know about this mechanism.
>     I think it is will do the job :)
>       I have probably to rewrite some parts pf my code to access my
>     variables through privateState.  no?
>
>
>     Thanks again
>     Abdelghani
>>     On 07 May 2018, at 13:15, [hidden email]
>>     <mailto:[hidden email]> wrote:
>>
>>
>>     Message: 1
>>     Date: Mon, 7 May 2018 13:43:56 +0200
>>     From: Pavel Krivanek <[hidden email]
>>     <mailto:[hidden email]>>
>>     To: Any question about pharo is welcome
>>     <[hidden email] <mailto:[hidden email]>>
>>     Subject: Re: [Pharo-users] Package extension. Adding instance
>>     variables to classes
>>     Message-ID:
>>     <CAHN2FzeMiBL4Y8asJ0XCjS2AQdxycoN+pbc+Hsd=[hidden email] <mailto:CAHN2FzeMiBL4Y8asJ0XCjS2AQdxycoN+pbc+Hsd=[hidden email]>>
>>     Content-Type: text/plain; charset="utf-8"
>>
>>     2018-05-07 12:25 GMT+02:00 Alidra Abdelghani via Pharo-users <
>>     [hidden email] <mailto:[hidden email]>>:
>>
>>>
>>>
>>>     ---------- P?eposlan? zpr?va ----------
>>>     From: Alidra Abdelghani <[hidden email]
>>>     <mailto:[hidden email]>>
>>>     To:[hidden email] <mailto:[hidden email]>
>>>     Cc:
>>>     Bcc:
>>>     Date: Mon, 7 May 2018 11:25:49 +0100
>>>     Subject: Package extension. Adding instance variables to classes
>>>     Hi,
>>>
>>>     I am working on a package named ClassNamesAnalyzer and I need to
>>>     add code
>>>     to third party classes in other packages (for instance the FAMIX-Core
>>>     package).
>>>     ?Extending? third party classes with methods is easy; I just need to
>>>     categorise my methods under the *ClassNamesAnalyzer protocole so that
>>>     loading my package will load them in the image.
>>>     However, if I want to add instance variables to theses classes,
>>>     they are
>>>     not there when I load the package in a new image.
>>>
>>>     *So my question is* : is there a way to include instance variables
>>>     addition to other packages in my package?
>>>
>>
>>     Currently not, you should use privateState
>>
>>
>>>     *Another question is* : is it good practice to add instance
>>>     variables to
>>>     classes in third party packages and is there a way to avoid it
>>>     (because I
>>>     am not very confortable with that idea)?
>>>
>>
>>     It is not, see FAMIXContainerEntity>>#definedAnnotationTypes how
>>     this issue
>>     is currently being solved using the privateState.
>>
>>     Cheers,
>>     -- Pavel
>>
>>
>>>
>>>     Thanks in advance,
>>>     Abdelghani
>
>
>
>
>
>
> --
>
>
>
> 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: Package extension. Adding instance variables to classes

Guillermo Polito

On Sun, May 13, 2018 at 6:37 PM, Herbert Vojčík <[hidden email]> wrote:


Guillermo Polito wrote:
Just be careful, that privateState thing looks like a Moose only Famix feature. It't not available in plain Pharo objects :)

In ES6 mailing list, they had this problem re how to do private state for objects, and it was shown that having private state is sort of isomorphic to having WeakMap indexed by objects. So in case of Pharo, I'd say using WeakIdentitityKeyDictionary can do the trick. Without resorting to any external dependency.

This works if the WeakMap is ephemeral. We should see in latest Pharo7 if Ephemerons are working.
 

Herby

On Wed, May 9, 2018 at 2:09 AM, Alidra Abdelghani via Pharo-users <[hidden email] <mailto:[hidden email]>> wrote:



    ---------- Forwarded message ----------
    From: Alidra Abdelghani <[hidden email]
    <mailto:[hidden email]>>
    To: Pavel Krivanek <[hidden email]
    <mailto:[hidden email]>>
    Cc: Any question about pharo is welcome <[hidden email]
    <mailto:[hidden email]>>
    Bcc:
    Date: Wed, 9 May 2018 01:09:06 +0100
    Subject: Re: Package extension. Adding instance variables to classes
    Hi Pavel,

    Thank you for your answer.
    I actually didn’t know about this mechanism.
    I think it is will do the job :)
      I have probably to rewrite some parts pf my code to access my
    variables through privateState.  no?


    Thanks again
    Abdelghani
    On 07 May 2018, at 13:15, [hidden email]
    <mailto:[hidden email]> wrote:


    Message: 1
    Date: Mon, 7 May 2018 13:43:56 +0200
    From: Pavel Krivanek <[hidden email]
    <mailto:[hidden email]>>
    To: Any question about pharo is welcome
    <[hidden email] <mailto:[hidden email]>>
    Subject: Re: [Pharo-users] Package extension. Adding instance
    variables to classes
    Message-ID:
    <CAHN2FzeMiBL4Y8asJ0XCjS2AQdxycoN+pbc+Hsd=[hidden email] <mailto:[hidden email]=[hidden email]>>
    Content-Type: text/plain; charset="utf-8"

    2018-05-07 12:25 GMT+02:00 Alidra Abdelghani via Pharo-users <
    [hidden email] <mailto:[hidden email]>>:



    ---------- P?eposlan? zpr?va ----------
    From: Alidra Abdelghani <[hidden email]
    <mailto:[hidden email]>>
    [hidden email] <mailto:[hidden email]>
    Cc:
    Bcc:
    Date: Mon, 7 May 2018 11:25:49 +0100
    Subject: Package extension. Adding instance variables to classes
    Hi,

    I am working on a package named ClassNamesAnalyzer and I need to
    add code
    to third party classes in other packages (for instance the FAMIX-Core
    package).
    ?Extending? third party classes with methods is easy; I just need to
    categorise my methods under the *ClassNamesAnalyzer protocole so that
    loading my package will load them in the image.
    However, if I want to add instance variables to theses classes,
    they are
    not there when I load the package in a new image.

    *So my question is* : is there a way to include instance variables
    addition to other packages in my package?


    Currently not, you should use privateState


    *Another question is* : is it good practice to add instance
    variables to
    classes in third party packages and is there a way to avoid it
    (because I
    am not very confortable with that idea)?


    It is not, see FAMIXContainerEntity>>#definedAnnotationTypes how
    this issue
    is currently being solved using the privateState.

    Cheers,
    -- Pavel



    Thanks in advance,
    Abdelghani






--

       

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




--

   

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