cormas icon indicating copy to clipboard operation
cormas copied to clipboard

Replace code refering to protocol names (pov, info probes, *,...) by pragmas

Open SergeStinckwich opened this issue 11 years ago • 6 comments

On Mon, Jun 30, 2014 at 1:06 PM, Nicolas Becu [email protected] wrote:

Thank you Serge.

Well to tell you the truth about why we use the name of protocols to identify certain methods instead of using pragmas.... it is because we discovered pragmas just some months ago (at least for me, thanks to Jean-François). And I would say that in my case, I'm still not so sure about how to use it. ;) But, we might switch to pragmas in a next cormas version.

Pragmas are dead simple ! You can see them as meta-data or properties attached to a specific method. For example for if you have the povFood method in the class X:

povFood <pointOfView>

^Color green

You just add: <pointOfView> pragma to the beginning of your method. This does not change the behaviour of your method.

You can then do a search of all pragmas in your system. If you want to know all the methods that have the <pointOfView> pragmas, you can evaluate :

Pragmas allNamed: #pointOfView in: X

that will return a collection of pragrmas #pointOfView available in the class X.

(Pragmas allNamed: #pointOfView in:X) collect: [:pragma | pragma method] if you want to have the collection of methods containing the

pointOfView pragma.

In you environnement window, you can build dynamically your menu by doing a search on pointOfView and info pragmas for example.

See http://www.cincomsmalltalk.com/main/documentation/VisualWorks/AppDevGuide.pdf page 4-25 for more information about Pragmas.

SergeStinckwich avatar Jul 01 '14 07:07 SergeStinckwich

As u understood, we used this bad habit (refering to protocol names) a lot. I recommand we start changing on a 'simple' example' and that would be the use of protocol name to fetch the probes methods.

Perhaps u could show us how to code this right and then we can use the same syntax for other cases. The code to change is in the probes method of CormasModel and of Cormas Entity. for the moment it is like this.

probes
^(self organization listAtCategoryNamed: #probes) asSortedCollection

Can u show us how to swith to using pragmas on this example. Thanks

nbecu avatar Jun 03 '15 07:06 nbecu

Load Cormas-Model-ECEC-SergeStinckwich.15 and Cormas-Core-SergeStinckwich.118, to have one example of using Pragma for probes.

SergeStinckwich avatar Jun 03 '15 08:06 SergeStinckwich

cool. easy indeed.

i've done the same for local probes (meaning, probes on the instances of an entity class). there is one in ECEC, it is on the energy of the foragers. The code works http://ws.stfx.eu/GZI5UVJQH0W6 but when i plot it, i get weird results

[image: Images intégrées 1]

2015-06-03 10:19 GMT+02:00 Serge Stinckwich [email protected]:

Load Cormas-Model-ECEC-SergeStinckwich.15 and Cormas-Core-SergeStinckwich.118, to have one example of using Pragma for probes.

— Reply to this email directly or view it on GitHub https://github.com/cormas/cormas/issues/10#issuecomment-108242153.

nbecu avatar Jun 03 '15 10:06 nbecu

I can't see the image. Images can't be used on github issues.

Sent from my iPhone

On 3 juin 2015, at 12:12, nbecu [email protected] wrote:

cool. easy indeed.

i've done the same for local probes (meaning, probes on the instances of an entity class). there is one in ECEC, it is on the energy of the foragers. The code works http://ws.stfx.eu/GZI5UVJQH0W6 but when i plot it, i get weird results

[image: Images intégrées 1]

2015-06-03 10:19 GMT+02:00 Serge Stinckwich [email protected]:

Load Cormas-Model-ECEC-SergeStinckwich.15 and Cormas-Core-SergeStinckwich.118, to have one example of using Pragma for probes.

— Reply to this email directly or view it on GitHub https://github.com/cormas/cormas/issues/10#issuecomment-108242153.

— Reply to this email directly or view it on GitHub.

SergeStinckwich avatar Jun 03 '15 10:06 SergeStinckwich

Copy from a email exchange between Peter, Serge and Nicolas


While prefixing the protocol name with "+" or "-" may not be common, using "public" or "private" prefix is actually rather common.

Yes, rather uncommon in the Smalltalk world. I don't remember Nicolas, what was the meaning of + and * ? '+' is used for public methods which we want modelers ta have access to easily when browsing classes

'* ' is the same as +, but more specifically dedicated to model users. I explain this a bit more. In Cormas, we provide tools for model users (none developers) to interact with the simulation. That is for example, clicking on an entity in the sapceInterface, and then having a list of methods that the model user can send to that entity.s SO those * methods are methods that appear in those interactive menus.

So you know understand that in Cormas we make a distinction between model developers, and model users. The last category is not supposed to code or to see code. Following this logic, we have a packaging tool in cormas. You can either create a cormas modeler package (which gives access to the browser and all vw tools), or model user package (which gives access to only one model and no access to the browser or other vw tools)

​It makes more sense to express this kind of information at protocol level, because then the user can quickly filter out which methods one can use. If it was in pragma then you would have to go through the methods one by one or write custom tool to filter the methods. And since some classes are rather large (CormasModel has 349 methods in Pharo), having a way to meaningfully separate them is essential.

Of course other approaches can be used... for example Spec (Pharo's UI builder) uses prefix "api" ("api", "api-building", "api-events", ...) to show which protocols are public; the rest is either in "private" or in unprefixed protocols.

nbecu avatar Nov 19 '15 09:11 nbecu

Related to #329

olekscode avatar Oct 03 '23 18:10 olekscode