On Tue, Oct 4, 2016 at 9:37 AM, CodeDmitry <dimamakhnin@gmail.com> wrote:
Oh! I see where I got confused now!
"static" variables in Pharo outlive their Playground call!
More than that. They outlive closing the image. The paradigm*** shift you need to make is that while the lifetime of "static" variables of a C/C++ program ends when program execution ends, and even though you stop and start execution of the VM, the execution of the "Image" *never* ends, it is only suspended. Try this experiment... In the System Browser... Morph subclass: #MyMorph instanceVariableNames: '' classVariableNames: '' package: 'AnExperiment' MyMorph>>step self right > Display width ifTrue: [ self left: 0 ]. self left: self left + 10. MyMorph>>stepTime ^100 In Playground... (m := MyMorph new) openInWorld. "After it has been running a while, Save & Quit the image**, then restart it. Notice the movement of the morph continues from where it left off." m delete. "...sometime later" **Even copy the image and changes to another machine they start it up there. *** and perhaps you might notice a change in your perception of "what is possible" from exposure in your course to the "dead" language of Smalltalk. And further, consider MyMorph is part of a control system for a nuclear power plant or financial trading system operating 365x24 and you want to change MyMorph from moving right to moving left. Consider how you would do that in C++ without stopping the system for even a second, compared to doing that in Pharo. Now Pharo may not be production ready (i.e. $$$) to run a nuclear power plant, but the concept of making such "live" changes to compiled code is now a concept you can carry forward to other disciplines. cheers -ben
If I call
Greeter greet. Greeter greeting: 'Hi!'. Greeter greet.
Even if greet sets greeting to an initial value if it is nil, it will forever then stay 'Hi!' until I change it or reset it.
So it is not unreasonable to get a response 'Hi! Hi!' in the playground even though 'Hi!' only gets set after greet is called, since the global state outlives the Transcript!