VB 和 VBA 的优缺点?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1348928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 10:44:32  来源:igfitidea点击:

Pros and Cons of VB & VBA?

vb.netvba

提问by PowerUser

On another programming related website, I saw this line in someone's signature. This is NOT the first time I've seen such sentiments, although this is the harshest:

在另一个与编程相关的网站上,我在某人的签名中看到了这一行。这不是我第一次看到这种情绪,尽管这是最严厉的:

"People who work in VB or any variant thereof are not programmers, they are circus chimps throwing feces into an IDE..."

“在 VB 或其任何变体中工作的人不是程序员,他们是将粪便扔进 IDE 的马戏团黑猩猩......”

VBA is my bread and butter and I can automate quite a bit of stuff with it. Yes, I know it lacks polish and some functionality, but why so much negativity toward it? On the flip side, what do other languages have that VB doesn't?

VBA 是我的面包和黄油,我可以用它自动化很多东西。是的,我知道它缺乏修饰和一些功能,但为什么对它如此消极呢?另一方面,其他语言有什么 VB 没有的?

回答by Juliet

VB6, VBScript, and VBA have the reputation because they just aren't industrial strength languages. Notably:

VB6、VBScript 和 VBA 之所以享有盛誉,是因为它们不是工业强度的语言。尤其:

  • No OOP. Sure, you have classes and modules, but no inheritance. VB isn't a low-level language, it needs real objects.
  • No first-class functions, so you can't even simulate OOP or polymorphism.
  • Lack of a well-developed class library. VB6 has a small library of built-in functions, and almost all other functionality is delegated to Windows calls or (usually pricey) third-party components.
  • Lousy error-handling. ON ERROR RESUME NEXT is a pox on the planet.
  • Although its not the fault of the language, VBA earned a bad reputation by association with MSAccess.
  • 没有面向对象。当然,你有类和模块,但没有继承。VB 不是低级语言,它需要真实的对象。
  • 没有一流的函数,因此您甚至无法模拟 OOP 或多态性。
  • 缺乏完善的类库。VB6 有一个小的内置函数库,几乎所有其他功能都委托给 Windows 调用或(通常是昂贵的)第三方组件。
  • 糟糕的错误处理。ON ERROR RESUME NEXT 是这个星球上的痘痘。
  • 尽管这不是语言的错,但 VBA 因与 MSAccess 的关联而赢得了不好的声誉。

Of course, VB wasn't really intendedto be an industrial strength language, so maybe nothing mentioned above is really proper criticism of the language at all. Fortunately VB.NET and the latest versions of VBA fix everything above, so VB.NET is on par with any other "serious" language in the marketplace.

当然,VB 并不是真的打算成为一种工业强度的语言,所以也许上面提到的任何东西都不是对这种语言的真正适当的批评。幸运的是,VB.NET 和最新版本的 VBA 修复了上述所有问题,因此 VB.NET 与市场上的任何其他“严肃”语言不相上下。



[anecdote]

[轶事]

In defense of VB, I find most people criticize the language just to go along with the status quo, not because they've actually used it.

在为 VB 辩护时,我发现大多数人批评该语言只是为了顺应现状,而不是因为他们实际使用过它。

A few years ago, in a chatroom, I ran across young neophyte railing against a VB6 developer for using such a crappy language. I innocently asked "what's wrong with VB".

几年前,在聊天室中,我遇到了年轻的新手栏杆反对使用这种蹩脚语言的 VB6 开发人员。我天真地问“VB 有什么问题”。

The first thing he said was "Because its a WINDOWS language!" So I pointed out that Borland Delphi is a Windows only language*, but I've never heard anyone malign it for that reason. (* There was a product called Kylix which cross-compiles to Linux, but its expensive, buggy, and discontinued. Its been a while since I've used Delphi, but last I'd heard, its still not ready for Linux.)

他说的第一句话是“因为它是一种WINDOWS语言!” 所以我指出 Borland Delphi 是一种仅适用于 Windows 的语言*,但我从未听说有人因此而诽谤它。(* 有一个叫做 Kylix 的产品,它可以交叉编译到 Linux,但它的价格昂贵,有缺陷,而且已经停产。我已经有一段时间没有使用 Delphi,但最后我听说它仍然没有准备好用于 Linux。)

So, he said "It has a HORRIBLE SYNTAX!" Is that really the reason people hate this language? I'd say Perl, Lisp, and C++ are worse on the eyes than VB.

所以,他说“它有一个可怕的语法!” 这真的是人们讨厌这种语言的原因吗?我会说 Perl、Lisp 和 C++ 在眼睛上比 VB 更糟糕。

Next, he says "Its too easy to learn!" Well, I'd consider that a point in favor of the language. I'll never write a GUI by hand if I have a drag-and-drop designer at my disposal. What else you got?

接下来,他说“太容易学了!” 好吧,我认为这是支持该语言的一点。如果我有一个拖放设计器可供我使用,我将永远不会手动编写 GUI。你还有什么?

So finally, grasping at straws, he comments "It has... no string manipulation functions". Left, Right, Mid, Replace, InStr and Trim. QED noob.

所以最后,他抓着稻草评论“它有……没有字符串操作功能”。左、右、中、替换、InStr 和修剪。QED菜鸟。

Interestingly, VB has features found some "hacker" languages, namely variant datatypes and duck typing. Compiled code performed reasonably well, interop between COM and native windows DLLs was easy, and the GUI editor basically set the bar for all future RAD development.

有趣的是,VB 有一些特性发现了一些“黑客”语言,即变体数据类型和鸭子类型。编译后的代码执行得相当好,COM 和本机 Windows DLL 之间的互操作很容易,而且 GUI 编辑器基本上为所有未来的 RAD 开发设置了标准。

[/anecdote]

[/轶事]

回答by Andrew Keeton

Read some of Joel Spolsky's articlesand you'll feel better about yourself. From his article Working on CityDesk, Part Three:

阅读乔尔·斯波尔斯基( Joel Spolsky) 的一些文章,您会对自己感觉更好。从他的文章在 CityDesk 上工作,第三部分

Visual Basic is an extremely productive way to write code, especially GUI code. Want bold text on a dialog box? It's one click in VB. Now try doing it in MFC. You have to create a subclassed control, it's a big mess, you have to know all about LOGFONTS and Windows window subclassing and a bunch of other things and you need about three lines of code once you have the magic class.

But many VB programs are spaghetti, either because they're done as quick and dirty one-offs, or because they're written by hack programmers without training in object oriented programming, or even structured programming.

What I wondered was, what happens if you take top-notch C++ programmers who dream in pointers, and let them code in VB. What I discovered at Fog Creek was that they become super-efficient coding machines. The code looks pretty good, it's object-oriented and robust, but you don't waste time using tools that are at a level lower than you need. I've spent years writing code for C++/MFC and years writing code in Visual Basic, and let me tell you, VB is just much, much more productive.

Visual Basic 是一种极其高效的代码编写方式,尤其是 GUI 代码。想要在对话框上加粗文本?在 VB 中它是一键式的。现在尝试在 MFC 中执行此操作。您必须创建一个子类控件,这是一团糟,您必须了解所有关于 LOGFONTS 和 Windows 窗口子类化以及一堆其他内容,并且一旦您拥有魔术类,您就需要大约三行代码。

但许多 VB 程序都是意大利面,要么是因为它们是一次性完成的,要么是因为它们是快速而肮脏的,要么是因为它们是由没有经过面向对象编程甚至结构化编程培训的黑客程序员编写的。

我想知道的是,如果你让那些梦想指针的顶尖 C++ 程序员让他们用 VB 编写代码,会发生什么。我在 Fog Creek 发现的是它们变成了超级高效的编码机器。代码看起来不错,它面向对象且健壮,但您不会浪费时间使用低于您需要的级别的工具。我花了数年时间为 C++/MFC 编写代码,并花费数年时间在 Visual Basic 中编写代码,让我告诉您,VB 的效率要高得多。

This simplicity attracts a lot of new programmers. Saying there are a lot of bad programmers using Visual Basic does not mean Visual Basic is a bad language; it simply means that Visual Basic is accessible to bad programmers (AKA new programmers).

这种简单性吸引了很多新程序员。说有很多糟糕的程序员使用 Visual Basic 并不意味着 Visual Basic 是一种糟糕的语言;它只是意味着糟糕的程序员(也称为新程序员)可以访问 Visual Basic。

回答by Ryan Lundy

I work in a place where all the code is C#, not VB .NET. One developer wrote most of the code. You know how he achieved this feat? Easy: He copied-and-pasted all over the place. A given method might have anywhere from a few to hundreds of copies throughout the system.

我在一个所有代码都是 C# 的地方工作,而不是 VB .NET。一位开发人员编写了大部分代码。你知道他是如何实现这一壮举的吗?简单:他到处复制粘贴。一个给定的方法在整个系统中可能有几个到数百个副本。

Good developers can be good in any language. Crappy developers can be crappy in any language.

优秀的开发人员可以擅长任何语言。糟糕的开发人员在任何语言中都可能很糟糕。

回答by Jim W

Also just to note that VB, VBA, and VB.NET are all three different languages even though they might share some similar syntax. There's no real difference between VB.NET and C# (besides the keywords/syntax), so we shouldn't lump VB (6 and before) and VBA in with VB.NET.

还要注意的是,VB、VBA 和 VB.NET 都是三种不同的语言,尽管它们可能共享一些相似的语法。VB.NET 和 C# 之间没有真正的区别(除了关键字/语法),所以我们不应该将 VB(6 及之前)和 VBA 与 VB.NET 混为一谈。

The real problem that many programmers have with "VB" (just say all 3 of the languages) is really more about the people using it. Most of the time "VB" programmers have less formal education and write sloppier code. That's not true for all "VB" programmers (and that doesn't mean there's not sloppy code written in C++, Java, C#, etc.). It's just the typical expectation that someone who doesn't use VB has when they hear about VB programs.

许多程序员对“VB”(只是说所有 3 种语言)的真正问题实际上更多地与使用它的人有关。大多数时候,“VB”程序员受过较少的正规教育,编写的代码比较草率。并非所有“VB”程序员都如此(这并不意味着没有用 C++、Java、C# 等编写的草率代码)。这只是不使用 VB 的人在听说 VB 程序时的典型期望。

回答by Brian MacKay

Meh, these are just religious bigots.

嗯,这些只是宗教偏执狂。

There is no one true language, and most experienced folks not only know that, but instantly recognize these statements as a glaring sign of inexperience.

没有一种真正的语言,大多数有经验的人不仅知道这一点,而且会立即认识到这些陈述是缺乏经验的明显标志。

回答by patros

Average developer quality seems to be inversely proportional to popularity of language * ease of use of language. VB is very easy, and is/was widely used.

平均开发人员质量似乎与语言的流行度 * 语言的易用性成反比。VB 非常简单,并且被/被广泛使用。

This is because A) there's a demand for coders in popular languages, so every employer has to either lower their standards, raise their pay or go without developers. B) people without a clue can still appear moderately productive in easy to use languages. There are enough libraries and GUI tools that they can slap together something that looks useful, even if it's complete garbage under the hood.

这是因为 A) 对流行语言的编码人员有需求,所以每个雇主都必须降低他们的标准,提高他们的工资,或者没有开发人员。B) 毫无头绪的人在使用易于使用的语言时仍能表现出中等生产力。有足够多的库和 GUI 工具,它们可以将看起来有用的东西拼凑在一起,即使它在底层完全是垃圾。

There's nothing inherently wrong with VB when used in the domains it was intended for, by people who know what they're doing. The same is true for almost any tool/language.

当人们知道自己在做什么时,VB 在其预期的领域中使用时并没有本质上的错误。几乎任何工具/语言都是如此。

回答by greg

I dislike the language, but that's mostly because I worked with a vb-like language which stripped out absolutely anythingthat might be considered an advantage and forced "best practices" that really didn't make sense.

我不喜欢这种语言,但这主要是因为我使用了一种类似 vb 的语言,这种语言绝对去除了任何可能被认为是优势的东西,并强制执行了真正没有意义的“最佳实践”。

The biggest problem I have with VB is that there is an almost direct track from clueless non-programmer -> part time Excel/Access scripter -> VBA "guru" -> VB "programmer" -> lead programmer on the most important project in the company.

我对 VB 的最大问题是,几乎可以直接从无知的非程序员 -> 兼职 Excel/Access 脚本员 -> VBA“大师” -> VB“程序员” -> 最重要项目的首席程序员公司。

Honestly I wouldn't have believed it if I didn't see someone follow that path right in front of my eyes. I even tried to mentor the guy so that he would be familiar with OOP, exception based error handling, etc. but he just dug his head in the sand and wrote everything procedurally because that had always worked for him.

老实说,如果我没有看到有人在我眼前走那条路,我是不会相信的。我什至试图指导这个人,让他熟悉 OOP、基于异常的错误处理等。但他只是埋头苦干,按程序编写所有内容,因为这对他一直有效。

I have had a chance to work with VB.Net and as long as I treated it like an object oriended .Net langauge first and VB second it wasn't so bad. It would never be my first choice for a new project, though.

我有机会使用 VB.Net,只要我把它当作一个面向对象的 .Net 语言,然后是 VB,它就没有那么糟糕。不过,它永远不会是我新项目的首选。

回答by Austin Salonen

I'm visiting SO in between writing VBScript code and that statement really rings true to me -- I am currently a circus chimp. If you don't know anything else, VB and its variants seem like great languages.

我正在编写 VBScript 代码之间访问 SO,这句话对我来说真的很真实——我目前是一只马戏团黑猩猩。如果您什么都不知道,VB 及其变体似乎是很棒的语言。

In my opinion, the reason for the negativity is one basic statement -- On Error Resume Next. This makes bad code a feature of the language. If it didn't have this, it wouldn't have near the bad publicity...

在我看来,否定的原因是一个基本陈述——On Error Resume Next。这使得糟糕的代码成为该语言的一个特征。如果它没有这个,它就不会接近糟糕的宣传......

回答by Matthew Vines

Most every developer I know has worked at one point or another with a VB developer, or a developer with a heavy VB background that just didn't have a clue. Unfortunately, as with most things, all we remember are the bad things about something. So we relate VB to bad programming.

我认识的大多数开发人员都曾与 VB 开发人员或具有深厚 VB 背景但一无所知的开发人员一起工作过。不幸的是,与大多数事情一样,我们所记得的都是关于某事的坏事。所以我们将 VB 与糟糕的编程联系起来。

It is certainly not true that all VB programmers are poor developers. But when everybody has stories about "This one old VB guy I used to work with." The stereotype is spread.

并非所有的 VB 程序员都是糟糕的开发人员。但是当每个人都有关于“我曾经与之共事的一位老 VB 家伙”的故事时。刻板印象正在蔓延。