如何寻址名称本质上以数字开头的变量名称?

发布于 2024-12-13 07:40:06 字数 439 浏览 0 评论 0原文

编写可维护代码的部分挑战是良好的命名约定。但有时一个好的、有意义的名称需要在变量的开头包含一个数字。以 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦与时光遇 2024-12-20 07:40:06

具体到您的示例,可以使用“退休”一词:

public Enum AccountType
  Savings = 0
  .
  .
  .
  Education529
  Retirement401k
  RetirementIRA
  RetirementRothIRA
  etc
End Enum

当然,这并不能真正回答一般问题,但也许您会发现它很有用。

作为一种模式或约定,可以在特定于域的数字前面加上特定于域的限定符。

Specific to your example, one could use the word Retirement:

public Enum AccountType
  Savings = 0
  .
  .
  .
  Education529
  Retirement401k
  RetirementIRA
  RetirementRothIRA
  etc
End Enum

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文