Reputation: 2965
What naming conventions are people using for variables that hold JSON-serializable objects? We'd like the name of the variable to remind us to only store information in the object that can be serialized into JSON without losing information. Applications include HTTP sessions, non-searchable database columns, data logging, and serializing restorable application state.
The obvious contenders, at least from the perspective of someone programming in Javascript for node.js, seem to fall short:
prefixJSON
- JSON is actually a serialization syntax, so this
would properly be a string in JSON format, not an objectprefixInfo
- info
is often used in node.js for any kind of map,
including ones that take functions and instances of ES6 classes.prefixMap
- Same issue as the info
suffixprefixData
- Doesn't really suggest a constraint on the typeThe best I can do is prefixJSONInfo
, prefixJSONData
, or prefixJSONObject
, but I was hoping for something more succinct and readable. The prefix may be lengthy and descriptive too.
This question mainly applies to programming languages that support variant-type variables, such as Javascript. These variables are meant to hold a mishmash, but the programmer needs to be reminded to limit the types of values that are thrown into the mishmash.
Upvotes: 0
Views: 1124
Reputation: 2270
In this case, it seems that a specific acronym might serve a good purpose.
JSONSerializable
written:
JSS or Jss
Examples:
prefixJss
customerDataJss
sessionInfoJss
Or maybe even:
JSONSerializableObject
prefixJSO
prefixJso
My $0.02. This might be more opinion based, as I don't think there are any globally accepted standards for these things. There are best practices, such as you mentioned (like short but descriptive). It's up to the developer or team to determine which short and descriptive versions they like (team preference).
Trust me tho, I understand how difficult naming things is sometimes. :)
Upvotes: 2