如何寻址名称本质上以数字开头的变量名称?
编写可维护代码的部分挑战是良好的命名约定。但有时一个好的、有意义的名称需要在变量的开头包含一个数字。以 401k 为例。没有其他名称可以称呼它,而且它的字面拼写有点俗气(FourOhOneK
)。
Public Enum AccountType
Savings = 0
Checking = 1
Certificate = 2
FourOhOneK = 3 'The odd one out
'_401k?
'n401k?
'Four01k?
'etc
End Enum
我可以自己对名字进行模糊处理,但是我会的,而且任何维护我的代码的人很可能有一天会被它绊倒。我的问题是,编程社区内是否有任何约定可以解决这个问题,或者这是否由个别程序员/公司政策决定?
Part of the challenge of writing maintainable code is a good naming convention. But sometimes a good, meaningful name involves a number being at the at the start of the variable. For example, take a 401k. Theres not another name in which to call it, and the literal spelling of it is kind of tacky (FourOhOneK
).
Public Enum AccountType
Savings = 0
Checking = 1
Certificate = 2
FourOhOneK = 3 'The odd one out
'_401k?
'n401k?
'Four01k?
'etc
End Enum
I can most certainly make my own obscurities for names, but I will and whoever maintains my code more than likely get tripped up on it one day. My question is, are there any conventions within the programming community that addresses this, or is this left up to the individual programmer/policies of the company that dictate this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
具体到您的示例,可以使用“退休”一词:
当然,这并不能真正回答一般问题,但也许您会发现它很有用。
作为一种模式或约定,可以在特定于域的数字前面加上特定于域的限定符。
Specific to your example, one could use the word Retirement:
Of course, that doesn't really answer the general question, but maybe you will find it useful.
As a pattern, or convention, one could prepend the domain-specific number with a domain-specific qualifier.