Remove global variable World
Last updated at 5:32 am UTC on 11 April 2018
[squeak-dev] The Inbox: EToys-dtl.316.mcz
Squeak
commits@source.squeak.org Fri, Dec 1, 2017 at 2:02 AM
David T. Lewis
Fri, Dec 1, 2017 at 2:23 AM
To: squeak-dev@lists.squeakfoundation.org
If this update passes muster, it means that we have completely removed all
dependencies on the global variable World in trunk:
Smalltalk garbageCollect.
(CompiledMethod allInstances
select: [:cm | (cm literals select: [:lit | #World = lit name]) size > 0]).
==> #()
It is now possible to do this, after which all project navigation will
continue to work as before:
Smalltalk removeKey: #World.
Compiler recompileAll.
After doing the above, put things back to normal with:
Smalltalk at: #World put: Project current world.
Dave
Marcel Taeumel
Thu, Apr 5, 2018 at 10:59 AM
Reply-To: The general-purpose Squeak developers list
To: Benoit St-Jean via Squeak-dev
Well, "ActiveWorld" is a dynamic variable that provides dynamic scope. Just like "ActiveEvent" and "ActiveHand". Useful and powerful in some cases. To be applied with caution. Yet, we have no alternative at the moment. Personally, I think we do not need any.
"World" is a global variable that we do not need anymore since the addition of "Project" and the projects concept some time ago.
Then, each visible morph has its own reference to a world. Usually, code should refer to this world when passing an instance as message argument.
- Currently, we have 6 senders of "World" left. We should make it 0.
- We also have 219 senders of "ActiveWorld" left. We should reduce that number to 10 or so in the core Morphic framework. Most of the other cases do not require ActiveWorld.
Dynamically-scoped variables are great for writing robust tests in such a primarily state-based environment. :-)
Best,
Marcel
Nicolas Cellier
Thu, Apr 5, 2018 at 10:36 AM
Reply-To: The general-purpose Squeak developers list
To: The general-purpose Squeak developers list
Hi Marcel,
yes, but the goal is rather to get rid of a global state (The single active World) and replace with a specific world passed by message or whatever.
In
Project current world
we have messages that provide indirection levels instead of a direct access by global scope.
This is maybe more robust to future change (in balance with less simplicity).
But we still have a global state (The active world).
Check for references to global 'World'
(CompiledMethod allInstances select: [ :e |
(e literals select: [ :lit | (lit isKindOf: Global)
and: [lit key == #World]]) isEmpty not]) size ==> 0