VB.NET 如何命名与其类型相关的变量?
只是想知道每个人都用什么来命名与已经描述性的类相关的变量?
例如:
Dim customersData as New CustomersData
Dim customersCollection as CustomersCollection
customersCollection = customersData.GetAll()
上面似乎没有任何设置规则在 C# 中是可以的,但在 VB 中不建议(尽管它会编译得很好)我见过像 'o' (oCustomersData) 以及 'my' (myCustomersData) 这样的前缀,但我我不确定我是否喜欢也看到过像 cd & 这样的缩写。 cc 的论点是,您所要做的就是将鼠标悬停在变量上以查看类型,但这严重损害了自我文档和可读性。
各位有何想法?
Just wondering what everyone uses to name variables that relate to an already descriptive class?
For example:
Dim customersData as New CustomersData
Dim customersCollection as CustomersCollection
customersCollection = customersData.GetAll()
There doesnt seem to be any set rule above is ok in C# but not advised in VB (although it will compile just fine) I have seen prefixes like 'o' (oCustomersData) aswell as 'my' (myCustomersData) but I'm not sure I like either have also seen abbreviations like cd & cc the argument being that all you have to do is hover over the variable to see the type but this seriously damages self documentation and readability.
Whats your thoughts folks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可能会选择:
按变量在当前上下文中的含义命名:
另一个例子可能是。
I would probably go with:
Name the variables by their meaning in the current context:
Another example might be.
我会这样编码:
我建议使用变量名称customers,因为我假设这是您将在整个方法中使用的变量,因此它更能描述您正在处理的内容。例如,稍后在代码中您可能有:
我以前没有见过这样的建议,而且我一直使用这种方法。
我从不给变量添加这样的前缀。我前缀的唯一变量是带有 _ 的类变量;例如_客户
您已经提供了答案。没有必要使用这样的短变量名,而且会损害可读性。如果使用短变量名的论点是打字速度,我认为学习正确打字并使用智能感知。
I would code it thus:
I'm suggesting the variable name customers because I'm assuming that is the variable you will be using throughout the method and therefore it is more descriptive of what you are working on. For example later in the code you might have:
I've not seen that advise before and I use this method all the time.
I never prefix variables like this. The only variables I prefix are class variables with _; eg _customers
You have provided the answer. There is no need and it's damaging to readability to use short variable names like this. If the argument to use short variable names is typing speed I'd argue learn to type properly and use intellisense.