Hi Everybody,
I try to be up-to-date with Pharo trends and releases. In Pharo 12, we
are switching to use fluid class declaration. Its' not easy to find
stuffs illustrating fluid API. I have spend many hours to browse Pharo
documentation, Github repos, slides, MOOcs, books, papers finding a way
to clearly explain this "new way" of declaring a class. All Pharo
introduction resources and Pharo 12 videos do not use fluid class
declaration but the "old" way. I also use (and let's say teach) Pharo in
my OOP lectures đ
If I'm not wrong, the fluid class declaration does no more explicitly
deal with instance (and class) variables. Instead, it deals now with
slots, tags, shared variables, traits,...At a fist look, I was
understanding that slots was a dynamic way to declare instance
variables. After reading some pieces of paper, and if I'm not wrong ,
slots are not really instance variables and shared variables are not
class variables.
Avoiding the old class declaration, i.e.
     Object subclass #SomeClassName instanceVariableNames: 'instaVar1
instVar2 ...' ...
is there a simple way to add an instance (or class) variable? Are
instance variables gone in Pharo? I assume I missed something, but what?
Many thanks. Cheers,
Herve
Hello Herve
I will add a description in the doc/ folder in P13 and may be P12.
If you need you can bring the menu on the class definition (put the caret on the class name) and select expand and you will see all the definition possibilities.
ïżŒïżŒ
For example
ArrayedCollection << #Array
layout: VariableLayout;
tag: 'Base';
package: 'Collections-Sequenceableâ
is the same as
ArrayedCollection variableSubclass: #Array
instanceVariableNames: ''
classVariableNames: ''
package: 'Collections-Sequenceable-Base'
For the rest, consider that this is the same with different names (because slots are compatible with instance variables).
So
Object << #Point
slots: { #x . #y };
tag: 'BasicObjects';
package: âKernel'
is the same as
Object subclass: #Point
instanceVariableNames: 'x y'
classVariableNames: ''
package: 'Kernel-BasicObjectsâ
and
WeakIdentityKeyDictionary << #ASTCache
sharedVariables: { #CacheMissStrategy };
tag: 'Parser';
package: 'AST-Core'
is the same as
WeakIdentityKeyDictionary subclass: #ASTCache
instanceVariableNames: ''
classVariableNames: 'CacheMissStrategy'
package: 'AST-Core-Parser'
What you see is that we do not have to specify empty lists :)
The only mandatary information is the class name and the package
Object << #Foo
package: âMyPackageâ
is a nice class definition.
The template show empty slots: {}; but this is not needed this is because some people do not like that type of slots: { };
BTW we use the new syntax in the Advanced Design Mooc and I started to migrate books too (not Pharo by Example because it is a big amount of work).
Tell us if this is clear for you.
I plan to change the slides of the Pharo mooc (Iâm currently converting them to use a nice slide syntax)
to use the fluid syntax.
Hi Everybody,
I try to be up-to-date with Pharo trends and releases. In Pharo 12, we are switching to use fluid class declaration. Its' not easy to find stuffs illustrating fluid API. I have spend many hours to browse Pharo documentation, Github repos, slides, MOOcs, books, papers finding a way to clearly explain this "new way" of declaring a class. All Pharo introduction resources and Pharo 12 videos do not use fluid class declaration but the "old" way. I also use (and let's say teach) Pharo in my OOP lectures đ
If you have links please send them and we will convert them.
If I'm not wrong, the fluid class declaration does no more explicitly deal with instance (and class) variables. Instead, it deals now with slots, tags, shared variables, traits,...At a fist look, I was understanding that slots was a dynamic way to declare instance variables.
A Slot is first an object representing an instance variable.
Now by default the programmer should use a symbol
so you go from
âx yâ to {#x . #y}
This syntax let us write more complex class definitions such as
SpPresenter << #SpDialogPresenter
slots: {
#parentWindow => WeakSlot .
#acceptAction .
#cancelAction .
#image };
package: 'Spec2-Dialogs'
here #parentWindow => WeakSlot creates a slot of the class WeakSlot (does not count for garbage collector)
After reading some pieces of paper, and if I'm not wrong , slots are not really instance variables and shared variables are not class variables.
Avoiding the old class declaration, i.e.
Object subclass #SomeClassName instanceVariableNames: 'instaVar1 instVar2 ...' ...
is there a simple way to add an instance (or class) variable?
you use slots: { . };
and
sharedVariables: are for classVarNames:
This is because sharedVariables are shared between the instance and class side
and like that we do not have the confusion of
class variables and metaclass instance variables.
For example TextConstants defines the following sharedVariables:
SharedPool << #TextConstants
slots: {};
sharedVariables: { #Ctrls . #Ctrlh . #CtrlR . #CtrlG . #DefaultMarginTabsArray . #Ctrlx . #Ctrlm . #Ctrlb . #BS . #CtrlL . #CtrlA . #CtrlW . #DefaultRule . #DefaultFontFamilySize . #Ctrlr . #Ctrlg . #CtrlQ . #EndOfRun . #CtrlF . #Italic . #Basal . #Ctrlw . #Ctrll . #Ctrla . #CtrlV . #CtrlK . #Bold . #Justified . #Ctrlf . #Ctrlq . #CtrlP . #CtrlE . #LeftMarginTab . #CtrlOpenBrackets . #DefaultSpace . #Ctrlv . #Ctrlk . #CtrlU . #CtrlJ . #Ctrlp . #Ctrle . #CtrlZ . #CtrlO . #CtrlD . #DefaultBaseline . #CrossedX . #LeftFlush . #Space . #Ctrlj . #CtrlT . #CtrlI . #RightFlush . #DefaultTab . #Ctrlu . #Centered . #Ctrlz . #Ctrlo . #Ctrld . #CtrlY . #CtrlN . #CtrlC . #Enter . #DefaultLineGrid . #ESC . #Ctrlt . #Ctrli . #CtrlS . #CtrlH . #Clear . #CR . #CtrlDigits . #DefaultMask . #Ctrln . #Ctrlc . #RightMarginTab . #CtrlM . #CtrlX . #BS2 . #Tab . #TextSharedInformation . #DefaultTabsArray . #Ctrly . #CtrlB };
tag: 'Base';
package: 'Text-Core'
ArrayedCollection subclass: #Text
instanceVariableNames: 'string runs'
classVariableNames: ''
poolDictionaries: 'TextConstants'
package: 'Text-Core-Base'
is now
ArrayedCollection << #Text
slots: { #string . #runs };
sharedPools: { TextConstants };
tag: 'Base';
package: 'Text-Core'
Because this is years that poolDictionaries do not exist anymore (they have SharedPool e.g. a special class holding sharedVariables)
Are instance variables gone in Pharo? I assume I missed something, but what?
No just empowered and backwards compatible.
Many thanks. Cheers,
Herve
Stéphane Ducasse
http://stephane.ducasse.free.fr
06 30 93 66 73
"If you knew today was your last day on earth, what would you do differently? ....ESPECIALLY if, by doing something different, today might not be your last day on earth.â Calvin & Hobbes
Hello Steph,
many thanks. It's now clear I think đ. My first understanding considering slots as objects representing instance variables wasn't bad. I wasn't sure because I was reading something to not consider slots as instance vars. Your answer lights me a lot đ.
HVE
Sep 22, 2024 19:18:24 stephane ducasse stephane.ducasse@inria.fr:
Hello Herve
I will add a description in the doc/ folder in P13 and may be P12.
If you need you can bring the menu on the class definition (put the caret on the class name) and select expand and you will see all the definition possibilities.Â
[cid:0A8FCA81-F1A9-490A-B051-8DE6F56A4E00][Capture 2024-09-22 at 19.06.35.png][cid:0A8FCA81-F1A9-490A-B051-8DE6F56A4E00][cid:EAC3AD2D-8376-429F-A59C-EE02E4ED5275][Capture 2024-09-22 at 19.06.44.png][cid:EAC3AD2D-8376-429F-A59C-EE02E4ED5275]
For exampleÂ
ArrayedCollection << #Array
layout: VariableLayout;
tag: 'Base';
package: 'Collections-Sequenceableâ
is the same asÂ
ArrayedCollection variableSubclass: #Array
instanceVariableNames: ''
classVariableNames: ''
package: 'Collections-Sequenceable-Base'
For the rest, consider that this is the same with different names (because slots are compatible with instance variables).
SoÂ
Object << #Point
slots: { #x . #y };
tag: 'BasicObjects';
package: âKernel'
is the same as
Object subclass: #Point
instanceVariableNames: 'x y'
classVariableNames: ''
package: 'Kernel-BasicObjectsâ
andÂ
WeakIdentityKeyDictionary << #ASTCache
sharedVariables: { #CacheMissStrategy };
tag: 'Parser';
package: 'AST-Core'
is the same asÂ
WeakIdentityKeyDictionary subclass: #ASTCache
instanceVariableNames: ''
classVariableNames: 'CacheMissStrategy'
package: 'AST-Core-Parser'
What you see is that we do not have to specify empty lists :)
The only mandatary information is the class name and the package
Object << #Foo
package: âMyPackageâ
is a nice class definition.
The template show empty slots: {}; but this is not needed this is because some people do not like that type of slots: { };
BTW we use the new syntax in the Advanced Design Mooc and I started to migrate books too (not Pharo by Example because it is a big amount of work).Â
Tell us if this is clear for you.Â
I plan to change the slides of the Pharo mooc (Iâm currently converting them to use a nice slide syntax)Â
to use the fluid syntax.Â
Hi Everybody,
I try to be up-to-date with Pharo trends and releases. In Pharo 12, we are switching to use fluid class declaration. Its' not easy to find stuffs illustrating fluid API. I have spend many hours to browse Pharo documentation, Github repos, slides, MOOcs, books, papers finding a way to clearly explain this "new way" of declaring a class. All Pharo introduction resources and Pharo 12 videos do not use fluid class declaration but the "old" way. I also use (and let's say teach) Pharo in my OOP lectures đ
If you have links please send them and we will convert them.Â
If I'm not wrong, the fluid class declaration does no more explicitly deal with instance (and class) variables. Instead, it deals now with slots, tags, shared variables, traits,...At a fist look, I was understanding that slots was a dynamic way to declare instance variables.
A Slot is first an object representing an instance variable.Â
Now by default the programmer should use a symbolÂ
so you go from
âx yâ to {#x . #y}
This syntax let us write more complex class definitions such as
SpPresenter << #SpDialogPresenter
slots: {
#parentWindow => WeakSlot .
#acceptAction .
#cancelAction .
#image };
package: 'Spec2-Dialogs'
here #parentWindow => WeakSlot creates a slot of the class WeakSlot (does not count for garbage collector)
After reading some pieces of paper, and if I'm not wrong , slots are not really instance variables and shared variables are not class variables.
Avoiding the old class declaration, i.e.
     Object subclass #SomeClassName instanceVariableNames: 'instaVar1 instVar2 ...' ...
is there a simple way to add an instance (or class) variable?
you use slots: { Â . Â };
andÂ
sharedVariables: are for classVarNames:Â
This is because sharedVariables are shared between the instance and class side
and like that we do not have the confusion ofÂ
class variables and metaclass instance variables.Â
For example TextConstants defines the following sharedVariables:
SharedPool << #TextConstants
slots: {};
sharedVariables: { #Ctrls . #Ctrlh . #CtrlR . #CtrlG . #DefaultMarginTabsArray . #Ctrlx . #Ctrlm . #Ctrlb . #BS . #CtrlL . #CtrlA . #CtrlW . #DefaultRule . #DefaultFontFamilySize . #Ctrlr . #Ctrlg . #CtrlQ . #EndOfRun . #CtrlF . #Italic . #Basal . #Ctrlw . #Ctrll . #Ctrla . #CtrlV . #CtrlK . #Bold . #Justified . #Ctrlf . #Ctrlq . #CtrlP . #CtrlE . #LeftMarginTab . #CtrlOpenBrackets . #DefaultSpace . #Ctrlv . #Ctrlk . #CtrlU . #CtrlJ . #Ctrlp . #Ctrle . #CtrlZ . #CtrlO . #CtrlD . #DefaultBaseline . #CrossedX . #LeftFlush . #Space . #Ctrlj . #CtrlT . #CtrlI . #RightFlush . #DefaultTab . #Ctrlu . #Centered . #Ctrlz . #Ctrlo . #Ctrld . #CtrlY . #CtrlN . #CtrlC . #Enter . #DefaultLineGrid . #ESC . #Ctrlt . #Ctrli . #CtrlS . #CtrlH . #Clear . #CR . #CtrlDigits . #DefaultMask . #Ctrln . #Ctrlc . #RightMarginTab . #CtrlM . #CtrlX . #BS2 . #Tab . #TextSharedInformation . #DefaultTabsArray . #Ctrly . #CtrlB };
tag: 'Base';
package: 'Text-Core'
ArrayedCollection subclass: #Text
instanceVariableNames: 'string runs'
classVariableNames: ''
poolDictionaries: 'TextConstants'
package: 'Text-Core-Base'
is now
ArrayedCollection << #Text
slots: { #string . #runs };
sharedPools: { TextConstants };
tag: 'Base';
package: 'Text-Core'
Because this is years that poolDictionaries do not exist anymore (they have SharedPool e.g. a special class holding sharedVariables)
Are instance variables gone in Pharo? I assume I missed something, but what?
No just empowered and backwards compatible.Â
Many thanks. Cheers,
Herve
Stéphane Ducasse
http://stephane.ducasse.free.fr
06 30 93 66 73
"If you knew today was your last day on earth, what would you do differently? ....ESPECIALLY if, by doing something different, today might not be your last day on earth.â Calvin & Hobbes
Thanks for your question.
I will add the following to the doc folder :)
https://github.com/pharo-project/pharo/pull/17151 with less typos :)
On 22 Sep 2024, at 22:01, stephane ducasse stephane.ducasse@inria.fr wrote:
Thanks for your question.
I will add the following to the doc folder :)
<fluid.pdf>
Stéphane Ducasse
http://stephane.ducasse.free.fr
06 30 93 66 73
"If you knew today was your last day on earth, what would you do differently? ....ESPECIALLY if, by doing something different, today might not be your last day on earth.â Calvin & Hobbes
https://github.com/pharo-project/pharo/pull/17151Â with less typos :)
On 22 Sep 2024, at 22:01, stephane ducasse stephane.ducasse@inria.fr wrote:
Thanks for your question.
I will add the following to the doc folder :)
<fluid.pdf>
Stéphane Ducasse
http://stephane.ducasse.free.fr
06 30 93 66 73
"If you knew today was your last day on earth, what would you do differently? ....ESPECIALLY if, by doing something different, today might not be your last day on earth.â Calvin & Hobbes