The way I understand it, global variables are the cleanest way of using both constant integers and constant strings, meaning that the method proposed would not actually make clean code cleaner.
When you give each state a name. There is no need for a global variable. See my previous post.
It's also slower since the lookup will work on int == int and not string.equals(string)
The idea was to use the hashcode of the string:
Now I'm not suggesting we use Strings instead, of course, hashes of Strings would be fine for this use case. This way, people could use both integers and strings.
This discussion is about adding 2 new methods in statebasedgame:
enterState(String) and addState(String)
addState(String) will take the hashcode of the state name and set it to the stateId,
enterState(String) calls the enterState(int) again using the hashcode.
I see real usage in this! please give it another thought