Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

What to name my package?

Discussion in 'Scripting' started by SquarePieStudios, Jun 17, 2015.

  1. SquarePieStudios

    SquarePieStudios

    Joined:
    Apr 22, 2015
    Posts:
    33
    Hey all,

    I have created a script (that I intend to throw up for free on the Asset Store) that manages a global dictionary of variables. These variables can be of any type, it has been generalized. Here are the list of features:
    • Global access to variables using a string id
    • Callback support for when a variable's value changes
    • Watch support for when a variable's value matches the watch value.
    There are about a million and one uses for something such as this, but I'm stuck trying to think of a name for the class/package. Here are my top picks so far:
    GlobalVariables
    GlobalData
    GameData
    GameState

    Any suggestions are welcome, because naming has and always will be the hardest part about programming :D

    Examples of how to use it with an int, but this can be used with any type:
    Code (CSharp):
    1.  
    2. //The example variable ID
    3. public string variableToListenTo = "VarID1";
    4. private void Start() {
    5.     //Set a listener for when the value of variableToListenTo is updated
    6.     GlobalVariables<int>.ListenForVariableUpdate(variableToListenTo, OutputListenerResult);
    7.     //Adds a watch for when the value of variableToListenTo matches the input value of 3.
    8.     GlobalVariableWatch<int>.AddValueWatch(variableToListenTo, 3, OutputWatch);
    9.     //Updates the variable's value from the default(0) to the value 2.
    10.     GlobalVariables<int>.UpdateVariable(variableToListenTo, 2);
    11.     // Console Output - Listener Variable(VarID1) -- 2
    12.  
    13.     //GlobalVariables_Int explicitely defines extra functionality for GlobalVariables<int>
    14.     //Here GlobalVariables_Int.AddValue defines adding to the value of the variable.
    15.     GlobalVariables_Int.AddValue(variableToListenTo, 1);
    16.     // Console Output - Listener Variable(VarID1) -- 3
    17.     //                - Watch Variable(VarID1) -- 3
    18.  
    19.     //Removes the listener for the variable
    20.     GlobalVariables_Int.UnlistenForVariableUpdate(variableToListenTo, OutputListenerResult);
    21.  
    22.     //Try calling after there are no more listeners
    23.     GlobalVariables_Int.UpdateVariable(variableToListenTo, 5);
    24.     //No Console Output
    25.  
    26.     //Removes the watcher for the variable
    27.     GlobalVariableWatch<int>.RemoveValueWatch(variableToListenTo, 3, OutputWatch);
    28.     //Try calling after there are no more watchers
    29.     GlobalVariables<int>.UpdateVariable(variableToListenTo, 3);
    30.     //No Console Output
    31. }
    32.  
    33. //Listener for when the value changes
    34. private void OutputListenerResult(string variableID, int value) {
    35.     Debug.LogErrorFormat("Listener Variable({0}) -- {1}", variableID, value);
    36. }
    37. //Watcher for when the value matches the requested value
    38. private void OutputWatch(string variableID, int value) {
    39.     Debug.LogErrorFormat("Watch Variable({0}) -- {1}", variableID, value);
    40. }
     
    Last edited: Jun 17, 2015
  2. sluice

    sluice

    Joined:
    Jan 31, 2014
    Posts:
    416
    I agree that naming (either be a variable, a method, a class or a package), is not always easy!
    Thank god for Refactoring!

    I think these ideas are too specific:
    GlobalData
    GameData
    GameState

    I think your package is "lower" than that, therefore the name should reflect that. It can be used to create a GameData/State manager for example.

    Some quick suggestions:
    -VariableManager / VarManager
    -VariableDictionary / VarDictionary
     
    VoidChimera and SquarePieStudios like this.
  3. SquarePieStudios

    SquarePieStudios

    Joined:
    Apr 22, 2015
    Posts:
    33
    Good suggestions. And I agree about it being "lower". I was actually in the process of building a larger project when this structure sort of fell out of it.

    I like VariableDictionary / VarDictionary
     
  4. SquarePieStudios

    SquarePieStudios

    Joined:
    Apr 22, 2015
    Posts:
    33
    Other ideas I've had:
    NamedVariable
    Code (CSharp):
    1. NamedVariable<int>.GetValue("testKey");
    Globals
    Code (CSharp):
    1. Globals<int>.GetValue("testKey");
    VariableTable
    Code (CSharp):
    1. VariableTable<int>.GetValue("testKey");

    Opinions or suggestions?
     
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,533
    Consider a name that's memorable and unique while still capturing the purpose of the package. It's likely that other packages also have a "GlobalVariable," for example. Even if yours in a unique namespace, it may be difficult for programmers to remember which "GlobalVariable" is which.

    I made this mistake with "Dialogue System for Unity". It's perfectly literal and descriptive. But, as often as not, one developer will say, "I'm using the Dialogue System for Unity," and another developer will ask, "Oh yeah? Which one?" since it sounds like a generic term rather than a product name.