VB.NET 如何命名与其类型相关的变量?

发布于 2024-11-19 18:18:24 字数 411 浏览 4 评论 0原文

只是想知道每个人都用什么来命名与已经描述性的类相关的变量?

例如:

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 技术交流群。

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

发布评论

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

评论(2

°如果伤别离去 2024-11-26 18:18:24

我可能会选择:

Dim custData as New CustomersData 'Better name might be CustomersDataService
Dim customers as CustomersCollection
customers = custData.GetAll()

按变量在当前上下文中的含义命名:
另一个例子可能是。

Dim excludedCustomers as CustomersCollection
excludedCustomers = custData.GetExcluded()

I would probably go with:

Dim custData as New CustomersData 'Better name might be CustomersDataService
Dim customers as CustomersCollection
customers = custData.GetAll()

Name the variables by their meaning in the current context:
Another example might be.

Dim excludedCustomers as CustomersCollection
excludedCustomers = custData.GetExcluded()
じее 2024-11-26 18:18:24

我会这样编码:

Dim customersData As New CustomersData
Dim customers As CustomersCollection
customers = customersData.GetAll()

我建议使用变量名称customers,因为我假设这是您将在整个方法中使用的变量,因此它更能描述您正在处理的内容。例如,稍后在代码中您可能有:

For each customer In customers
    ....
Next

不建议在 VB 中使用(尽管它可以编译得很好)

我以前没有见过这样的建议,而且我一直使用这种方法。

我见过像“o”(oCustomersData) 和“my”(myCustomersData) 这样的前缀,但我不确定我是否喜欢其中任何一个。

我从不给变量添加这样的前缀。我前缀的唯一变量是带有 _ 的类变量;例如_客户

我还看到过像 cd & 这样的缩写。 cc 的论点是,您所要做的就是将鼠标悬停在变量上即可查看类型,但这严重损害了自我文档和可读性。

您已经提供了答案。没有必要使用这样的短变量名,而且会损害可读性。如果使用短变量名的论点是打字速度,我认为学习正确打字并使用智能感知。

I would code it thus:

Dim customersData As New CustomersData
Dim customers As CustomersCollection
customers = customersData.GetAll()

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:

For each customer In customers
    ....
Next

Not advised in VB (although it will compile just fine)

I've not seen that advise before and I use this method all the time.

I have seen prefixes like 'o' (oCustomersData) as well as 'my' (myCustomersData) but I'm not sure I like either.

I never prefix variables like this. The only variables I prefix are class variables with _; eg _customers

I 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.

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.

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