Thanks On Thu, Sep 28, 2017 at 6:36 PM, Denis Kudriashov <[hidden email]> wrote:
|
In reply to this post by Stephane Ducasse-3
2017-09-28 21:12 GMT+02:00 Stephane Ducasse <[hidden email]>:
Done.
|
tx! On Fri, Sep 29, 2017 at 9:58 AM, Denis Kudriashov <[hidden email]> wrote:
|
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:
|
I implement query for annotations of concrete class. So right now if you will do
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]>:
|
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 |
2017-10-03 14:38 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. 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. |
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 |
2017-10-03 16:15 GMT+02:00 Sean P. DeNigris <[hidden email]>: Denis Kudriashov wrote Yes, Margitte class side descriptions can be implemented as ClassAnnotations. What I don't understand is the difference between, for example: 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:
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:
For example I have 187 annotation instances in Calypso. They should not be instantiated during lookup |
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 |
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
|
2017-10-04 9:48 GMT+02:00 Guillermo Polito <[hidden email]>:
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 not understand the question. You supposed to return an instance of the annotation from the "annotating method".
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?
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).
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:
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?
|
Denis Kudriashov wrote
> 2017-10-04 9:48 GMT+02:00 Guillermo Polito < > guillermopolito@ > >: > >> 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 |
2017-10-04 11:56 GMT+02:00 Henrik Sperre Johansen <[hidden email]>: Denis Kudriashov wrote Then have different pragma traversers capable of creating the actual menus / 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
|
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 |
In reply to this post by Denis Kudriashov
On Wed, Oct 4, 2017 at 10:51 AM, Denis Kudriashov <[hidden email]> wrote:
Nope, imagine you do RenamePackageCommand class>>
If your someInstVarOfMyClass changes its value after the creation of the Annotation object, you're dead.
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.
|
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 Which means restriction to me because I could not simply use a block in the place of pragma.
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#.
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! |
In reply to this post by Guillermo Polito
2017-10-04 14:43 GMT+02:00 Guillermo Polito <[hidden email]>:
Yes, you are right. And I have similar cases in Calypso. For some command sub-hierarchy I define shortcut like:
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.
|
Free forum by Nabble | Edit this page |