[Ann] Class meta annotations

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

Re: [Ann] Class meta annotations

Stephane Ducasse-3
Thanks


On Thu, Sep 28, 2017 at 6:36 PM, Denis Kudriashov <[hidden email]> wrote:
2017-09-28 18:17 GMT+02:00 Denis Kudriashov <[hidden email]>:
2017-09-25 17:57 GMT+02:00 Denis Kudriashov <[hidden email]>:
2017-09-25 17:38 GMT+02:00 Stephane Ducasse <[hidden email]>:
I agree with guille. We should just called them class annotations.

Denis what is a declared instance (is it an object returned by the method having the annotation)
but can we find a better name. 

My idea that the method with pragma #classMetaAnnotation is the declaration of annotation. Internally this declaration creates instance of specified annotation which cached by system. And users access all these declared instances for reflection purposes.


Maybe #registeredInstances would be better?

So I rename these messages too. I think it's better. 

 
Also annotation has inst var declarationSelector.  
 
may be effectiveInstances?

 I don't like this name. I not understand "effective" in that context.
 


On Mon, Sep 25, 2017 at 5:09 PM, Guillermo Polito <[hidden email]> wrote:
Why calling them meta-annotation and not just annotation? Annotations are in general already meta :)

On Mon, Sep 25, 2017 at 5:01 PM, Denis Kudriashov <[hidden email]> wrote:
Hi.

I glad to present one class package which introduces reusable mechanism for first class annotations.

The project can be found on github https://github.com/dionisiydk/ClassMetaAnnotation.
And I tried to describe why it is needed in my blog http://dionisiydk.blogspot.fr/2017/09/class-meta-annotations.html.

And here is overview:

Every annotation should be subclass of ClassMetaAnnotation. To attach it to class you create new class side method which will return an instance of the annotation. Method should be marked with pragma #classMetaAnnotation:

MyClass class>>specialAnnotation
<classMetaAnnotation>
^MySpecialAnnotation new

To query annotations from system there are two methods:

1) You can ask concrete annotation class for all declared instances:

MySpecialAnnotation declaredInstances

2) You can ask given class for all attached annotations:

MyClass metaAnnotations

Every annotation includes information about annotated class and the selector of declaring method.
All annotations are cached. So it is cheap to query them. There are extra messages to enumerate annotations using block.

Now let's discuss it. I think it can be good addition for the Pharo 7. Especially that it is very small code.

Also I would like to thank Marcus who helps me realize this concept in Commander and Calypso which I start simplify with this library.

Best regards,
Denis



--

   

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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13






Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Denis Kudriashov
In reply to this post by Stephane Ducasse-3

2017-09-28 21:12 GMT+02:00 Stephane Ducasse <[hidden email]>:
I would not use meta because you would not write annotationAnnotations :)
and annotations is meta by its name.

classAnnotation is much better than metaAnnotation 

Done.
 

Stef


On Thu, Sep 28, 2017 at 5:40 PM, Denis Kudriashov <[hidden email]> wrote:
So I renamed it to ClassAnnotation with all related names.

But I keep meta prefix in #metaAnnotations Class extension to avoid general name:
MyClass metaAnnotations   

You can check updated readme for details https://github.com/dionisiydk/ClassAnnotation

2017-09-26 17:31 GMT+02:00 Stephane Ducasse <[hidden email]>:
;)

On Tue, Sep 26, 2017 at 1:28 PM, Ben Coman <[hidden email]> wrote:
Shhh... The first rule of meta-club is we don't talk about meta-club.


cheers -ben


On Mon, Sep 25, 2017 at 11:09 PM, Guillermo Polito <[hidden email]> wrote:
Why calling them meta-annotation and not just annotation? Annotations are in general already meta :)

On Mon, Sep 25, 2017 at 5:01 PM, Denis Kudriashov <[hidden email]> wrote:
Hi.

I glad to present one class package which introduces reusable mechanism for first class annotations.

The project can be found on github https://github.com/dionisiydk/ClassMetaAnnotation.
And I tried to describe why it is needed in my blog http://dionisiydk.blogspot.fr/2017/09/class-meta-annotations.html.

And here is overview:

Every annotation should be subclass of ClassMetaAnnotation. To attach it to class you create new class side method which will return an instance of the annotation. Method should be marked with pragma #classMetaAnnotation:

MyClass class>>specialAnnotation
<classMetaAnnotation>
^MySpecialAnnotation new

To query annotations from system there are two methods:

1) You can ask concrete annotation class for all declared instances:

MySpecialAnnotation declaredInstances

2) You can ask given class for all attached annotations:

MyClass metaAnnotations

Every annotation includes information about annotated class and the selector of declaring method.
All annotations are cached. So it is cheap to query them. There are extra messages to enumerate annotations using block.

Now let's discuss it. I think it can be good addition for the Pharo 7. Especially that it is very small code.

Also I would like to thank Marcus who helps me realize this concept in Commander and Calypso which I start simplify with this library.

Best regards,
Denis



--

   

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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13






Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Stephane Ducasse-3
tx!

On Fri, Sep 29, 2017 at 9:58 AM, Denis Kudriashov <[hidden email]> wrote:

2017-09-28 21:12 GMT+02:00 Stephane Ducasse <[hidden email]>:
I would not use meta because you would not write annotationAnnotations :)
and annotations is meta by its name.

classAnnotation is much better than metaAnnotation 

Done.
 

Stef


On Thu, Sep 28, 2017 at 5:40 PM, Denis Kudriashov <[hidden email]> wrote:
So I renamed it to ClassAnnotation with all related names.

But I keep meta prefix in #metaAnnotations Class extension to avoid general name:
MyClass metaAnnotations   

You can check updated readme for details https://github.com/dionisiydk/ClassAnnotation

2017-09-26 17:31 GMT+02:00 Stephane Ducasse <[hidden email]>:
;)

On Tue, Sep 26, 2017 at 1:28 PM, Ben Coman <[hidden email]> wrote:
Shhh... The first rule of meta-club is we don't talk about meta-club.


cheers -ben


On Mon, Sep 25, 2017 at 11:09 PM, Guillermo Polito <[hidden email]> wrote:
Why calling them meta-annotation and not just annotation? Annotations are in general already meta :)

On Mon, Sep 25, 2017 at 5:01 PM, Denis Kudriashov <[hidden email]> wrote:
Hi.

I glad to present one class package which introduces reusable mechanism for first class annotations.

The project can be found on github https://github.com/dionisiydk/ClassMetaAnnotation.
And I tried to describe why it is needed in my blog http://dionisiydk.blogspot.fr/2017/09/class-meta-annotations.html.

And here is overview:

Every annotation should be subclass of ClassMetaAnnotation. To attach it to class you create new class side method which will return an instance of the annotation. Method should be marked with pragma #classMetaAnnotation:

MyClass class>>specialAnnotation
<classMetaAnnotation>
^MySpecialAnnotation new

To query annotations from system there are two methods:

1) You can ask concrete annotation class for all declared instances:

MySpecialAnnotation declaredInstances

2) You can ask given class for all attached annotations:

MyClass metaAnnotations

Every annotation includes information about annotated class and the selector of declaring method.
All annotations are cached. So it is cheap to query them. There are extra messages to enumerate annotations using block.

Now let's discuss it. I think it can be good addition for the Pharo 7. Especially that it is very small code.

Also I would like to thank Marcus who helps me realize this concept in Commander and Calypso which I start simplify with this library.

Best regards,
Denis



--

   

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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13







Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Guillermo Polito
Ok, I'm back from vacations so I'll give a comment other than what I did :P.

First I like it.

Second, how does it work with respect to inheritance? I mean, if I have for example:

ClassAnnotation subclass: MyFrameworkAnnotation.

And then

MyFrameworkAnnotation subclass: MyConcreteAnnotation1.
MyFrameworkAnnotation subclass: MyConcreteAnnotation2.

Can I query all my annotations or should do an isKindOf: by hand?

On Fri, Sep 29, 2017 at 1:10 PM, Stephane Ducasse <[hidden email]> wrote:
tx!

On Fri, Sep 29, 2017 at 9:58 AM, Denis Kudriashov <[hidden email]> wrote:

2017-09-28 21:12 GMT+02:00 Stephane Ducasse <[hidden email]>:
I would not use meta because you would not write annotationAnnotations :)
and annotations is meta by its name.

classAnnotation is much better than metaAnnotation 

Done.
 

Stef


On Thu, Sep 28, 2017 at 5:40 PM, Denis Kudriashov <[hidden email]> wrote:
So I renamed it to ClassAnnotation with all related names.

But I keep meta prefix in #metaAnnotations Class extension to avoid general name:
MyClass metaAnnotations   

You can check updated readme for details https://github.com/dionisiydk/ClassAnnotation

2017-09-26 17:31 GMT+02:00 Stephane Ducasse <[hidden email]>:
;)

On Tue, Sep 26, 2017 at 1:28 PM, Ben Coman <[hidden email]> wrote:
Shhh... The first rule of meta-club is we don't talk about meta-club.


cheers -ben


On Mon, Sep 25, 2017 at 11:09 PM, Guillermo Polito <[hidden email]> wrote:
Why calling them meta-annotation and not just annotation? Annotations are in general already meta :)

On Mon, Sep 25, 2017 at 5:01 PM, Denis Kudriashov <[hidden email]> wrote:
Hi.

I glad to present one class package which introduces reusable mechanism for first class annotations.

The project can be found on github https://github.com/dionisiydk/ClassMetaAnnotation.
And I tried to describe why it is needed in my blog http://dionisiydk.blogspot.fr/2017/09/class-meta-annotations.html.

And here is overview:

Every annotation should be subclass of ClassMetaAnnotation. To attach it to class you create new class side method which will return an instance of the annotation. Method should be marked with pragma #classMetaAnnotation:

MyClass class>>specialAnnotation
<classMetaAnnotation>
^MySpecialAnnotation new

To query annotations from system there are two methods:

1) You can ask concrete annotation class for all declared instances:

MySpecialAnnotation declaredInstances

2) You can ask given class for all attached annotations:

MyClass metaAnnotations

Every annotation includes information about annotated class and the selector of declaring method.
All annotations are cached. So it is cheap to query them. There are extra messages to enumerate annotations using block.

Now let's discuss it. I think it can be good addition for the Pharo 7. Especially that it is very small code.

Also I would like to thank Marcus who helps me realize this concept in Commander and Calypso which I start simplify with this library.

Best regards,
Denis



--

   

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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+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

Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Denis Kudriashov
I implement query for annotations of concrete class. So right now if you will do 

MyFrameworkAnnotation registeredInstances 

it will return only MyFrameworkAnnotation instances. It will not include any MyConcreteAnnotation instance.
We can change this part if it is better to work with all subclasses. Or we can introduce another message like registeredSubInstances with consistency to general allSubInstances method,

Another detail about inheritance: subclasses inherit superclass annotations and override them.




2017-10-03 12:10 GMT+02:00 Guillermo Polito <[hidden email]>:
Ok, I'm back from vacations so I'll give a comment other than what I did :P.

First I like it.

Second, how does it work with respect to inheritance? I mean, if I have for example:

ClassAnnotation subclass: MyFrameworkAnnotation.

And then

MyFrameworkAnnotation subclass: MyConcreteAnnotation1.
MyFrameworkAnnotation subclass: MyConcreteAnnotation2.

Can I query all my annotations or should do an isKindOf: by hand?

On Fri, Sep 29, 2017 at 1:10 PM, Stephane Ducasse <[hidden email]> wrote:
tx!

On Fri, Sep 29, 2017 at 9:58 AM, Denis Kudriashov <[hidden email]> wrote:

2017-09-28 21:12 GMT+02:00 Stephane Ducasse <[hidden email]>:
I would not use meta because you would not write annotationAnnotations :)
and annotations is meta by its name.

classAnnotation is much better than metaAnnotation 

Done.
 

Stef


On Thu, Sep 28, 2017 at 5:40 PM, Denis Kudriashov <[hidden email]> wrote:
So I renamed it to ClassAnnotation with all related names.

But I keep meta prefix in #metaAnnotations Class extension to avoid general name:
MyClass metaAnnotations   

You can check updated readme for details https://github.com/dionisiydk/ClassAnnotation

2017-09-26 17:31 GMT+02:00 Stephane Ducasse <[hidden email]>:
;)

On Tue, Sep 26, 2017 at 1:28 PM, Ben Coman <[hidden email]> wrote:
Shhh... The first rule of meta-club is we don't talk about meta-club.


cheers -ben


On Mon, Sep 25, 2017 at 11:09 PM, Guillermo Polito <[hidden email]> wrote:
Why calling them meta-annotation and not just annotation? Annotations are in general already meta :)

On Mon, Sep 25, 2017 at 5:01 PM, Denis Kudriashov <[hidden email]> wrote:
Hi.

I glad to present one class package which introduces reusable mechanism for first class annotations.

The project can be found on github https://github.com/dionisiydk/ClassMetaAnnotation.
And I tried to describe why it is needed in my blog http://dionisiydk.blogspot.fr/2017/09/class-meta-annotations.html.

And here is overview:

Every annotation should be subclass of ClassMetaAnnotation. To attach it to class you create new class side method which will return an instance of the annotation. Method should be marked with pragma #classMetaAnnotation:

MyClass class>>specialAnnotation
<classMetaAnnotation>
^MySpecialAnnotation new

To query annotations from system there are two methods:

1) You can ask concrete annotation class for all declared instances:

MySpecialAnnotation declaredInstances

2) You can ask given class for all attached annotations:

MyClass metaAnnotations

Every annotation includes information about annotated class and the selector of declaring method.
All annotations are cached. So it is cheap to query them. There are extra messages to enumerate annotations using block.

Now let's discuss it. I think it can be good addition for the Pharo 7. Especially that it is very small code.

Also I would like to thank Marcus who helps me realize this concept in Commander and Calypso which I start simplify with this library.

Best regards,
Denis



--

   

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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13


Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Sean P. DeNigris
Administrator
In reply to this post by Denis Kudriashov
Denis Kudriashov wrote
> I also realized that this library automatically adds annotations to
> packages because we are now able annotate manifest classes

This all sounds very cool, but would you mind explaining the motivation a
bit? For example, isn't a manifest class itself meta-information about a
package? What does this new feature enable us to do for/with classes and
packages that we couldn't do before? Thanks!



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Denis Kudriashov
2017-10-03 14:38 GMT+02:00 Sean P. DeNigris <[hidden email]>:
Denis Kudriashov wrote
> I also realized that this library automatically adds annotations to
> packages because we are now able annotate manifest classes

This all sounds very cool, but would you mind explaining the motivation a
bit? For example, isn't a manifest class itself meta-information about a
package? What does this new feature enable us to do for/with classes and
packages that we couldn't do before? Thanks!

I thought I explained it in my blog. But I know that I am a bad writer.
For Commander examples look at github https://github.com/dionisiydk/Commander/tree/dev. It's still draft and not full. 

About packages It was just an idea. 
Yes, Manifest is a meta information itself. But you are not able to extend it from different packages like class extensions. I don't know where it can be needed. But with class annotation approach you can do it. 
Actually it is the main feature required for Commander: UI packages extend commands from domain packages with information how to access and execute them from UI. It makes commands reusable.


Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Sean P. DeNigris
Administrator
Denis Kudriashov wrote
> I thought I explained it in my blog... But I know that I am a bad writer.

Ah, sorry I forgot to re-read the blog and was trying to refresh my
understanding just based on this thread. I wouldn't say the post was poorly
written, just seemed to assume a prior familiarity with the inherent value
of class annotations.

From what I understand, what you're describing sounds very Magritte-like.
What I don't understand is the difference between, for example:

    CmdCommand class>>#activators ^ self classAnnotations select: [ :each |
each isKindOf: CmdCommandActivationStrategy ]

and a <commandActivationStrategy> pragma which signifies a message returning
an appropriate object.



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Denis Kudriashov

2017-10-03 16:15 GMT+02:00 Sean P. DeNigris <[hidden email]>:
Denis Kudriashov wrote
> I thought I explained it in my blog... But I know that I am a bad writer.

Ah, sorry I forgot to re-read the blog and was trying to refresh my
understanding just based on this thread. I wouldn't say the post was poorly
written, just seemed to assume a prior familiarity with the inherent value
of class annotations.

From what I understand, what you're describing sounds very Magritte-like.

Yes, Margitte class side descriptions can be implemented as ClassAnnotations. 
 
What I don't understand is the difference between, for example:

    CmdCommand class>>#activators ^ self classAnnotations select: [ :each |
each isKindOf: CmdCommandActivationStrategy ]

In Commander we need to query all activation strategies which are defined for particular Command. So here we skip any other annotations.
But the common case is to query all instances of concrete kind of activation strategy. For example to find shortcut for given keymap:

CmdShortcutCommandActivation allAvailableInContext: aToolContext do: [:eachShortcutStrategy |
eachShortcutStrategy keyCombination matches: aKey ]  


and a <commandActivationStrategy> pragma which signifies a message returning
an appropriate object.

I also thought that I explained it in the blog :).
If you will use method pragma then you will repeat logic of this library:
In your code you will need evaluate found pragma methods. You will need to handle broken methods. You will need to implement inheritance, how to correctly query overrides.
And if performance is important you will need to implement kind of cache and invalidation logic.

So ClassAnnotation solves these problems. 
All annotations are cached and cheap for queries:

CmdShortcutCommandActivation registeredInstances == CmdShortcutCommandActivation registeredInstances.

For example I have 187 annotation instances in Calypso. They should not be instantiated during lookup

Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Sean P. DeNigris
Administrator
Denis Kudriashov wrote
> If you will use method pragma then you will repeat logic of this library:
> In your code you will need...

So it sounds like it's pragmas++ - the functionality of pragmas plus some
other stuff you may need that you'd have to roll on your own



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Guillermo Polito
I'd even call them First class pragmas from that point of view :P

I wonder what are the side-effects of instantiating the annotation yourself in a method.

specialAnnotationExample
    <classAnnotation>
    ^MySpecialAnnotation new

I mean, I understand we can use the class state to initialize the annotation. But the fact that the annotation is cached after its first instantiation means that the annotation will not necessarily evolve as the class evolves. Do we want annotations to be stateless? Or depend only in literals?

I wonder then what is the main difference with

specialAnnotationExample
    <classAnnotation: MySpecialAnnotation>

And what is the impact of having an annotation with parameters.

On Tue, Oct 3, 2017 at 9:02 PM, Sean P. DeNigris <[hidden email]> wrote:
Denis Kudriashov wrote
> If you will use method pragma then you will repeat logic of this library:
> In your code you will need...

So it sounds like it's pragmas++ - the functionality of pragmas plus some
other stuff you may need that you'd have to roll on your own



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html




--

   

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: [Ann] Class meta annotations

Denis Kudriashov
2017-10-04 9:48 GMT+02:00 Guillermo Polito <[hidden email]>:
I'd even call them First class pragmas from that point of view :P

Yes.
But we decided avoid pragma related names here. Because in future it can be possible to add normal pragmas into the class definition.
 

I wonder what are the side-effects of instantiating the annotation yourself in a method.

specialAnnotationExample
    <classAnnotation>
    ^MySpecialAnnotation new

I not understand the question. You supposed to return an instance of the annotation from the "annotating method".
 

I mean, I understand we can use the class state to initialize the annotation. But the fact that the annotation is cached after its first instantiation means that the annotation will not necessarily evolve as the class evolves.

Cache is updated after related class changes: method added, removed and so on (driven by PragmaCollector logic). So outdated annotations should not exist.
Is it what you ask?
 
Do we want annotations to be stateless? Or depend only in literals?

I want annotations to be any object with any state inside. Of course you will be restricted by what is visible from the class side. But in "annotating method" you can create any complex object (see below).


I wonder then what is the main difference with

specialAnnotationExample
    <classAnnotation: MySpecialAnnotation>

And what is the impact of having an annotation with parameters.

Generally it is same like having pragma with parameters. 
But with annotation you are not restricted by literal objects. So annotation parameters can be anything.

And it is important feature for Commander. 
For example I need instance of KMKeyCombination to define shortcut for command. So I just use normal expression for this:

RenamePackageCommand class>>packageBrowserShortcutActivation
<classAnnotation> 
^CmdShortcutCommandActivation by: $r meta for: ClyPackageBrowserContext
 
It will be very complicated to express it with method pragma and it will be restricted anyway.

Another important point is that class annotation is first class object which means that you can add behaviour to it. With method pragma you can not.
For example shortcut annotation includes method to check given key event and execute command if it is satisfied.

Is it now clear?


On Tue, Oct 3, 2017 at 9:02 PM, Sean P. DeNigris <[hidden email]> wrote:
Denis Kudriashov wrote
> If you will use method pragma then you will repeat logic of this library:
> In your code you will need...

So it sounds like it's pragmas++ - the functionality of pragmas plus some
other stuff you may need that you'd have to roll on your own



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html




--

   

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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13


Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Henrik Sperre Johansen
Denis Kudriashov wrote
> 2017-10-04 9:48 GMT+02:00 Guillermo Polito &lt;

> guillermopolito@

> &gt;:
>
>> I'd even call them First class pragmas from that point of view :P
>>
>
> Yes.
> But we decided avoid pragma related names here. Because in future it can
> be
> possible to add normal pragmas into the class definition.
>
>
>>
>> I wonder what are the side-effects of instantiating the annotation
>> yourself in a method.
>>
>> specialAnnotationExample
>>    
> <classAnnotation>
>>     ^MySpecialAnnotation new
>>
>
> I not understand the question. You supposed to return an *instance* of the
> annotation from the "annotating method".
>
>
>>
>> I mean, I understand we can use the class state to initialize the
>> annotation. But the fact that the annotation is cached after its first
>> instantiation means that the annotation will not necessarily evolve as
>> the
>> class evolves.
>>
>
> Cache is updated after related class changes: method added, removed and so
> on (driven by PragmaCollector logic). So outdated annotations should not
> exist.
> Is it what you ask?
>
>
>> Do we want annotations to be stateless? Or depend only in literals?
>>
>
> I want annotations to be any object with any state inside. Of course you
> will be restricted by what is visible from the class side. But in
> "annotating method" you can create any complex object (see below).
>
>
>> I wonder then what is the main difference with
>>
>> specialAnnotationExample
>>    
> <classAnnotation: MySpecialAnnotation>
>>
>> And what is the impact of having an annotation with parameters.
>>
>
> Generally it is same like having pragma with parameters.
> But with annotation you are not restricted by literal objects. So
> annotation parameters can be anything.
>
> And it is important feature for Commander.
> For example I need instance of KMKeyCombination to define shortcut for
> command. So I just use normal expression for this:
>
> RenamePackageCommand class>>packageBrowserShortcutActivation
> <classAnnotation>
> ^CmdShortcutCommandActivation by: *$r meta* for: ClyPackageBrowserContext
>
>
> It will be very complicated to express it with method pragma and it will
> be
> restricted anyway.

Would it?
With pure method tags, you'd do something like:
SomeClass >> #renamePackage: aPackage
<command: 'Rename package'
 category: 'Package'
 order: 25
 shortcut: #($r meta)>
... method renaming package here ...

Then have different pragma traversers capable of creating the actual menus /
commands invoking such methods.
(And yes, all caching/invalidation would be the responsibility of the
traverser(s) if necessary, as usual)

Cheers,
Henry



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Denis Kudriashov

2017-10-04 11:56 GMT+02:00 Henrik Sperre Johansen <[hidden email]>:
Denis Kudriashov wrote
> Generally it is same like having pragma with parameters.
> But with annotation you are not restricted by literal objects. So
> annotation parameters can be anything.
>
> And it is important feature for Commander.
> For example I need instance of KMKeyCombination to define shortcut for
> command. So I just use normal expression for this:
>
> RenamePackageCommand class>>packageBrowserShortcutActivation
> <classAnnotation>
> ^CmdShortcutCommandActivation by: *$r meta* for: ClyPackageBrowserContext
>
>
> It will be very complicated to express it with method pragma and it will
> be
> restricted anyway.

Would it?
With pure method tags, you'd do something like:
SomeClass >> #renamePackage: aPackage
<command: 'Rename package'
 category: 'Package'
 order: 25
 shortcut: #($r meta)>
... method renaming package here ...  
Then have different pragma traversers capable of creating the actual menus /
commands invoking such methods.

So instead of simple subclassing of ClassAnnotation you would suggest me to implement pragma traversal/interpreter?
I would prefer first. It gives me for free the object with any structure without any tricky literal interpretation logic.
For me annotation is just obviously simpler solution. 

Also try to think how to support blocks in parameters with pragma approach. And how fun would be to debug them. It is for the question about "restricted anyway". Really, with annotations you have normal smalltalk code for annotating classes. No magic. And implementation is really simple.

(And yes, all caching/invalidation would be the responsibility of the
traverser(s) if necessary, as usual) 

Cheers,
Henry

Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Henrik Sperre Johansen
Denis Kudriashov wrote
> 2017-10-04 11:56 GMT+02:00 Henrik Sperre Johansen <

> henrik.s.johansen@

>>:
>
>> Denis Kudriashov wrote
>> > Generally it is same like having pragma with parameters.
>> > But with annotation you are not restricted by literal objects. So
>> > annotation parameters can be anything.
>> >
>> > And it is important feature for Commander.
>> > For example I need instance of KMKeyCombination to define shortcut for
>> > command. So I just use normal expression for this:
>> >
>> > RenamePackageCommand class>>packageBrowserShortcutActivation
>> >
> <classAnnotation>
>> > ^CmdShortcutCommandActivation by: *$r meta* for:
>> ClyPackageBrowserContext
>> >
>> >
>> > It will be very complicated to express it with method pragma and it
>> will
>> > be
>> > restricted anyway.
>>
>> Would it?
>> With pure method tags, you'd do something like:
>> SomeClass >> #renamePackage: aPackage
>>
> <command: 'Rename package'
>>
>   category: 'Package'
>>  order: 25
>>  shortcut: #($r meta)>
>> ... method renaming package here ...
>
> Then have different pragma traversers capable of creating the actual menus
> /
>> commands invoking such methods.
>>
>
> So instead of simple subclassing of ClassAnnotation you would suggest me
> to
> implement pragma traversal/interpreter?
> I would prefer first. It gives me for free the object with any structure
> without any tricky literal interpretation logic.
> For me annotation is just obviously simpler solution.

A traverser doesn't have to be a lot of work;
http://forum.world.st/Having-comments-for-pragma-tp4902987p4903058.html

Denis Kudriashov wrote
> Also try to think how to support blocks in parameters with pragma
> approach.
> And how fun would be to debug them.
>  It is for the question about
> "restricted anyway".

You wouldn't need them. What to do with the tag, is up to the traverser.
For instance, #perform'ing one of the literal args on the domain class
traverser creates, returning an appropriate block, if strictly necessary.

Denis Kudriashov wrote
>  Really, with annotations you have normal smalltalk
> code for annotating classes. No magic. And implementation is really
> simple.

Same with a traverser; the normal smalltalk code to create your domain
objects  is simply in a different place; the traverser part of the package
defining said domain, rather than as an extension method marked with a tag.

I guess it's best to just agree to disagree, and since you're the one
implementing... ;)
Looking forward to trying it out!

Cheers,
Henry



--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html

Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Guillermo Polito
In reply to this post by Denis Kudriashov


On Wed, Oct 4, 2017 at 10:51 AM, Denis Kudriashov <[hidden email]> wrote:
2017-10-04 9:48 GMT+02:00 Guillermo Polito <[hidden email]>:
I'd even call them First class pragmas from that point of view :P

Yes.
But we decided avoid pragma related names here. Because in future it can be possible to add normal pragmas into the class definition.
 

I wonder what are the side-effects of instantiating the annotation yourself in a method.

specialAnnotationExample
    <classAnnotation>
    ^MySpecialAnnotation new

I not understand the question. You supposed to return an instance of the annotation from the "annotating method".
 

I mean, I understand we can use the class state to initialize the annotation. But the fact that the annotation is cached after its first instantiation means that the annotation will not necessarily evolve as the class evolves.

Cache is updated after related class changes: method added, removed and so on (driven by PragmaCollector logic). So outdated annotations should not exist.
Is it what you ask?

Nope, imagine you do


RenamePackageCommand class>>packageBrowserShortcutActivation
<classAnnotation> 
^CmdShortcutCommandActivation by: $r meta for: someInstVarOfMyClass

 
If your someInstVarOfMyClass changes its value after the creation of the Annotation object, you're dead.

 
Do we want annotations to be stateless? Or depend only in literals?

I want annotations to be any object with any state inside. Of course you will be restricted by what is visible from the class side. But in "annotating method" you can create any complex object (see below).


I wonder then what is the main difference with

specialAnnotationExample
    <classAnnotation: MySpecialAnnotation>

And what is the impact of having an annotation with parameters.

Generally it is same like having pragma with parameters. 
But with annotation you are not restricted by literal objects. So annotation parameters can be anything.

And it is important feature for Commander. 
For example I need instance of KMKeyCombination to define shortcut for command. So I just use normal expression for this:

RenamePackageCommand class>>packageBrowserShortcutActivation
<classAnnotation> 
^CmdShortcutCommandActivation by: $r meta for: ClyPackageBrowserContext
 
It will be very complicated to express it with method pragma and it will be restricted anyway.

Another important point is that class annotation is first class object which means that you can add behaviour to it.

Yes, I get that and I like the idea that the Annotation is not just a command pattern with an execute method. It can be more than that and that's the interesting part of it. Otherwise a normal pragma can just replace it.
 
With method pragma you can not.
For example shortcut annotation includes method to check given key event and execute command if it is satisfied.

Is it now clear?


On Tue, Oct 3, 2017 at 9:02 PM, Sean P. DeNigris <[hidden email]> wrote:
Denis Kudriashov wrote
> If you will use method pragma then you will repeat logic of this library:
> In your code you will need...

So it sounds like it's pragmas++ - the functionality of pragmas plus some
other stuff you may need that you'd have to roll on your own



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html




--

   

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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+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

Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Denis Kudriashov
In reply to this post by Henrik Sperre Johansen

2017-10-04 14:34 GMT+02:00 Henrik Sperre Johansen <[hidden email]>:
Denis Kudriashov wrote
>> Would it?
>> With pure method tags, you'd do something like:
>> SomeClass >> #renamePackage: aPackage
>>
> <command: 'Rename package'
>>
>   category: 'Package'
>>  order: 25
>>  shortcut: #($r meta)>
>> ... method renaming package here ...
>
> Then have different pragma traversers capable of creating the actual menus
> /
>> commands invoking such methods.
>>
>
> So instead of simple subclassing of ClassAnnotation you would suggest me
> to
> implement pragma traversal/interpreter?
> I would prefer first. It gives me for free the object with any structure
> without any tricky literal interpretation logic.
> For me annotation is just obviously simpler solution.

A traverser doesn't have to be a lot of work;
http://forum.world.st/Having-comments-for-pragma-tp4902987p4903058.html

Denis Kudriashov wrote
> Also try to think how to support blocks in parameters with pragma
> approach.
> And how fun would be to debug them.
>  It is for the question about
> "restricted anyway".

You wouldn't need them. What to do with the tag, is up to the traverser.
For instance, #perform'ing one of the literal args on the domain class
traverser creates, returning an appropriate block, if strictly necessary.

Which means restriction to me because I could not simply use a block in the place of pragma.
 

Denis Kudriashov wrote
>  Really, with annotations you have normal smalltalk
> code for annotating classes. No magic. And implementation is really
> simple.

Same with a traverser; the normal smalltalk code to create your domain
objects  is simply in a different place; the traverser part of the package
defining said domain, rather than as an extension method marked with a tag.

But example with #($r meta) shows that it is not normal smalltalk code. I could not put halt here (I expect that halt will work, but it will debug interpreter code instead of expression). 
Also extension methods here is a very important feature and not just a mechanism. Because it provides the way how to annotate existing classes from external packages. It is pretty cool feature which not exists in java or C#.


I guess it's best to just agree to disagree, and since you're the one
implementing... ;)

Ok, Henrik. But last note:
Pragma is low level annotation mechanism and actually more than annotation which was discussed many times in past. 
But with this library I tried to generalise the way how we use pragmas to annotate classes. 
Of course you can use pragmas to implement my examples. But I argue that it will require more complex code.
 
Best regards,
Denis 

Looking forward to trying it out!

Reply | Threaded
Open this post in threaded view
|

Re: [Ann] Class meta annotations

Denis Kudriashov
In reply to this post by Guillermo Polito
2017-10-04 14:43 GMT+02:00 Guillermo Polito <[hidden email]>:

 

I mean, I understand we can use the class state to initialize the annotation. But the fact that the annotation is cached after its first instantiation means that the annotation will not necessarily evolve as the class evolves.

Cache is updated after related class changes: method added, removed and so on (driven by PragmaCollector logic). So outdated annotations should not exist.
Is it what you ask?

Nope, imagine you do


RenamePackageCommand class>>packageBrowserShortcutActivation
<classAnnotation> 
^CmdShortcutCommandActivation by: $r meta for: someInstVarOfMyClass

 
If your someInstVarOfMyClass changes its value after the creation of the Annotation object, you're dead.

Yes, you are right.
And I have similar cases in Calypso. For some command sub-hierarchy I define shortcut like:

 ^CmdShortcutCommandActivation by: self defaultShorcurtCombination for: ClassBrowserContext.

And command annotations are not updated when I change the method #defaultShorcurtCombination. So I manually reset cache after such changes.
Would be interesting to find solution for this. 
 

 
Do we want annotations to be stateless? Or depend only in literals?

I want annotations to be any object with any state inside. Of course you will be restricted by what is visible from the class side. But in "annotating method" you can create any complex object (see below).


I wonder then what is the main difference with

specialAnnotationExample
    <classAnnotation: MySpecialAnnotation>

And what is the impact of having an annotation with parameters.

Generally it is same like having pragma with parameters. 
But with annotation you are not restricted by literal objects. So annotation parameters can be anything.

And it is important feature for Commander. 
For example I need instance of KMKeyCombination to define shortcut for command. So I just use normal expression for this:

RenamePackageCommand class>>packageBrowserShortcutActivation
<classAnnotation> 
^CmdShortcutCommandActivation by: $r meta for: ClyPackageBrowserContext
 
It will be very complicated to express it with method pragma and it will be restricted anyway.

Another important point is that class annotation is first class object which means that you can add behaviour to it.

Yes, I get that and I like the idea that the Annotation is not just a command pattern with an execute method. It can be more than that and that's the interesting part of it. Otherwise a normal pragma can just replace it.
 
With method pragma you can not.
For example shortcut annotation includes method to check given key event and execute command if it is satisfied.

Is it now clear?


On Tue, Oct 3, 2017 at 9:02 PM, Sean P. DeNigris <[hidden email]> wrote:
Denis Kudriashov wrote
> If you will use method pragma then you will repeat logic of this library:
> In your code you will need...

So it sounds like it's pragmas++ - the functionality of pragmas plus some
other stuff you may need that you'd have to roll on your own



-----
Cheers,
Sean
--
Sent from: http://forum.world.st/Pharo-Smalltalk-Developers-f1294837.html




--

   

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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+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: <a href="tel:+33%206%2052%2070%2066%2013" value="+33652706613" target="_blank">+33 06 52 70 66 13


12