英文:
Naming variables which represent json
问题
我正在为一个变量命名,JsonArray versionsJA = jsonObject.get("versions").getAsJsonArray()
这里是否有任何适当的命名约定可用?我的意思是是否有比名称versionsJA
更好的选择?
在变量名称中以某种形式包含变量类型是个好主意吗?
在这里,JA
表示JsonArray。是否有更好的备选名称?
英文:
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?
答案1
得分: 1
除非在您的程序中还有其他版本变量,否则只需将其命名为version。在变量名称中编码变量的类型被认为是不良风格,因为它增加了不必要的冗余。在编程中,我们希望将每一点信息仅保存在一个地方,而在这种情况下,我们可以在声明中看到它是一个JSON数组。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论