[Proposal]To avoid global name clashes when used with custom blocks

Using global variables within Snap! custom blocks can be useful at times but can lead to issues.

This is prompted by me wanting to create a fast decimal ->hex convertor that uses a large lookup table and I want to hold the lookup table as a global var so it only gets created once to speed things up

Note: I've a pretty good idea that Jens would prefer us not to do this at all but lets not get into that here :slight_smile:

So, the main published library to do this is the Colors and Crayons one.

It avoids any possible name space clashes by prefixing the variables with a pen icon
image

I'm suggesting that we come up with some sort of agreed protocol (between us Snap! users) to do something similar if we publish custom blocks/libraries for others to use

So my suggestion is to prefix any such global vars with our usernames (as they should be unique)
image

Does anyone have an alternative suggestion to achieve the same result

That makes for some very long variable names. Potentially we could do, like, two to four letters of our username instead. In some projects and stuff, I identify with "PJ21" rather than "pajamaclaws21" simply because of length.

Has the disadvantage of possibly not being unique

And the var would only be being used within your own custom block so if it's long - does it matter?

But, in practice, not many people are going to be using this technique (as it's a last resort) so using a shortened prefix would 99.99% work in practice :slight_smile:

Hmm... How about a script pic tracks the username that put the script pic, so when the variable is dragged from the script pic to a project, it puts the username in the variable name?

I think your over-thinking things but lets see what you can come up with :slight_smile:

It's a perfectly reasonable idea.

We can agree it's an idea :slight_smile:

It would be impressive to see it even if it turns out not to be a good idea

Uhhhh, Ok, that's fine.

There. Done.

There are bazillions of Unicode characters. Plenty of room for creativity. :~)