VB/VBA 变量声明编码标准 - 空白

发布于 2024-08-11 15:41:56 字数 357 浏览 2 评论 0原文

像这样在 VB/VBA 中声明变量的意义是什么:

Private m_sName         As String
Private m_lAge          As Long

相反;

Private m_sName As String
Private m_lAge As Long

我正在开发一个项目,到目前为止,该项目一直在使用后者,并且早在我加入该项目之前就已经完成了。两名新开发人员加入了团队并开始使用前者。我以前见过这样的分页并且想知道;它的传统是什么?它有什么优点/缺点?我自己的偏好一直是后者,并且仍然如此,这与其他方面一样,都是为了保持一致性。

What is the significance of declaring variables in VB/VBA like so:

Private m_sName         As String
Private m_lAge          As Long

As opposed to;

Private m_sName As String
Private m_lAge As Long

I am working on a project which up to now uses the latter, and has done since long before I joined the project. Two new developers have joined the team and have begun to use the former. I have seen such pagination previously and wondered; what is its heritage and what advantages/disadvantages does it have? My own preference has always been the latter and remains so, as much for consistency as anything else.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

冰雪之触 2024-08-18 15:41:57

在代码编辑器更加愚蠢并且只是文本编辑器的时代,维护代码的“列样式”(前一个示例)更容易。然而,即使如此,当更改需要手动重新组织代码时,这可能会很痛苦。

但后来智能感知和自动格式化的出现,使得维护“列式”格式化代码变得非常困难。更改行中的某些内容,IDE 会自动消除“不必要的”空白。

我完全是为了可读性,但不是到这个程度,坚持后一种风格。

In the days when code editors were much dumber and were little more the text editors it was easier to maintain the "column-style" (the former example) of code. However even then it could be a pain when changes would require manual re-orginisation of code.

But then intellisense and auto-formatting came along and made it really difficult to maintain the "column-style" formatting code. Change something in the line and the IDE automatically eliminated "unnecessary" white-space.

I'm all for readability but not to this extent, stick with latter style.

清秋悲枫 2024-08-18 15:41:57

这只是可读性的问题。
VB/VBA 中的多个空格将被忽略。

我会使用前者,因为它更具可读性,但 Visual Studio 有自己的格式规则,并且会删除多余的空格,因此我必须使用第二种形式。 :)

It's only a matter of readability.
Multiple whitespaces in VB/VBA are ignored.

I'd use the former because it's more readable, but Visual Studio has its own formatting rules and will remove extra whitespaces, so I have to use the second form. :)

怕倦 2024-08-18 15:41:57

这是旧 C 时代的编码约定,当时您有无穷无尽的结构,并且希望看到类型和变量名称在同一列中开始。随心所欲!

This is a coding convention from old C-days, where you had endless structs and you wanted to see the types and variable names starting in the same column. Do as you prefer!

坦然微笑 2024-08-18 15:41:57

在我看来,更容易阅读。前者可以清楚地看到变量名称和类型,而后者随着变量声明的增多而变得更加困难。

Easier to read, in my opinion. You can clearly see the variable name and type in the former, whilst the latter becomes more difficult with more variable declarations.

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