0

I am naming a variable JsonArray versionsJA = jsonObject.get("versions").getAsJsonArray()
Is there any proper naming convention that can be done here? I mean something better than the name versionsJA?
Is it a good idea to include the type of variable in the name in some form?
Here the JA means JsonArray
Any alternate name that could be better?

nick
  • 107
  • 6

1 Answers1

1

Unless there are other version variables in your program, simply name it version. Encoding the type of a variable in its name is considered bad style since it adds unnecessary redundancy. In programming we want to keep each bit of information in only one place and in this case we can see in the declaration that it is a JSON array.

August Karlstrom
  • 10,773
  • 7
  • 38
  • 60
  • But suppose jsonObject.get("version") returns a version jsonElement which contains a primitive like "version": "1.0.2" So if I store the jsonElement in a variable that could also be called version and the actual string value 1.0.2 is also called version. This is where the confusion arises. I end up naming the first one as versionJsonElement Not sure if that is a good approach or if there is a better approach. Here there will be two variables `versionJsonElement` and `version` -> stores the actual string value – nick May 30 '23 at 07:53
  • I didn't notice the plural in your question: *versions* rather than *version*. Couldn't you use *versions* for the array and *version* for one of the values (strings)? – August Karlstrom May 30 '23 at 10:58