On Sat, Jun 25, 2016 at 8:08 AM, stepharo <[email protected]> wrote: > > >> +1. I can't stress enough how useful it is to make pragmas real >> selectors with implementations and to try and apply them using >> perform:withArguments:. That's when their real power comes in. >> >> For example, if you have some method that wants to be added to some tool, >> make its pragma a message with all the information you need to add it as >> arguments (things like its position or priority relative to other >> additions, its name in the list of components, an icon to use, a string for >> fly-by help) and then implement a builder class whose methods match these >> pragmas so that when the builder performs the pragma it adds the method to >> the tool, in a given position, with a given icon and fly-by help etc. >> >> In most other systems method annotations are simply that, just passive >> labels. But in Smalltalk these are executable. You can browse for senders >> and implementors, you can execute them using a visitor pattern. Much more >> powerful. >> >> Hi eliot > > For the pragmas paper I read about annotation in Java and from what I > learned they are more powerful in Java. > They can annotate any language elements and they can also be executed (I > have to discuss with a Java expert to get it). > > In Java you *cannot* annotate any language element. You can annotate class, methods, instance variables, method arguments and temporaries and packages.
Then when I take an annotation, for example an hibernate annotation: @Entity@Table(name = "EMPLOYEE") In the case of Hibernate, these annotation are for a class and they are used at *runtime* to bind the class instances with database entries (elements of this class are stored in the table EMPLOYEE). Now I've never seen anyone doing that, but as you can access the annotation at runtime, and you can extract from the annotation its name and its parameters (for example you could extract "Table" and "name -> EMPLOYEE". Then, using the Java reflective features, you can do something like: method = obj.getClass().getMethod(methodName, param1.class, param2.class, ..); method.invoke(obj, arg1, arg2,...); And this way you execute a method named "Table", "name" or "EMPLOYEE" with the parameter you want, as you could execute a method from any string matching a method name. We have the same primitive in Pharo on CompiledMethod. I would not say that pragmas are more powerful in Java. Can you give an example of something you can do with the Java annotation that you can't do with Pharo pragmas ? In Slang we use pragma to annotate argument and temporary variables and it works just fine. When you describe in Pharo classes and instance variables using Magritte you can do the same thing as just annotating them. Stef > >
