uliwitness / Stacksmith

An intuitive software erector kit targeted at people new to programming, but with enough potential to stay useful once they've learned, inspired by HyperCard.
http://stacksmith.org
131 stars 13 forks source link

Shared user properties #107

Open uliwitness opened 3 years ago

uliwitness commented 3 years ago

A lot of shared information was traditionally kept in globals in HyperTalk. In modern languages, there are many smaller scopes that you can use to avoid namespace collisions between different modules. We already have user properties as a storage that is namespaced to that instance. (a property "foo" on cd btn 1 can be completely different than one of the same name on cd btn 2)

It seems like it could be a good first step to add something like that to user properties. To provide some sort of "shared" user property that can be addressed just like any other user property, but whose value is shared by multiple objects.

Can we find a good syntax for that? Or is it enough to just tell scripters to create an invisible object to hold all those properties and access them from another?

Maybe something like

create cd btn "sharedStorage"
define property "shared1" of cd btn "sharedStorage"

create cd btn "storageAccessor1"
set sharedPropertyContainer of cd btn "storageAccessor1" to cd btn "sharedStorage"
set shared1 of cd btn "storageAccessor1" to 42 -- actually changes shared1 of cd btn "sharedStorage"

?

One major advantage of this would be the brevity of saying my shared1 inside "storageAccessor1"'s script instead of having to write shared1 of cd btn "sharedStorage". Of course it could also be surprising if there was a "storageAccessor2" whose shared1 property would suddenly also change.

uliwitness commented 3 years ago

Bonus thought: Could this be made a general mechanism, where not just user properties, but the entire script of the sharedStorage is inherited? Kind of a blueprint/class style deal? Or would that be mixing apples and oranges? Given the script would often also need to access non-shared properties, how would you conveniently declare those if they aren't inherited? Why would they be shared and not copied/inherited?