tags:

views:

1158

answers:

20

To me, Visual Basic seems clumsy, ugly, error-prone, and difficult to read. I'll let others explain why. While VB.net has clearly been a huge leap forward for the language in terms of features, I still don't understand why anyone would choose to code in VB over, say, C#.

However, I still see (what seems to be) the vast majority of commercial web apps from "MS shops" are built in VB. I could stand corrected on this, but VB still seems more popular than it deserves.

Can anyone help answer any (or all) of these questions:

  • Am I missing something with VB? Is it easier to learn, or "friendlier" than C#? Are there features I don't know about?
  • Why is VB/VB.net so frequently used today, especially in web projects?
A: 

To name a few:

  • ease of use
  • familiar name (basic was one of the first popular computer programming languages)
  • don't underestimate microsoft marketing
Gamecat
+7  A: 

Historically the VB development environment was a quick and effective way of building certain types of applications (e.g. GUI apps). That led to it being a very popular choice. I think VB was the most used language during its heyday (e.g. VB6).

With that kind of installed base, it's hardly surprising there is still a lot of work going on in it.

dommer
+1 afaics VB6 and especially the VS IDE provided a (very) low barrier to entry which created a generation of new coders, with all the problems and possibilities therein
annakata
+2  A: 

However ugly any given language may be the reasons for sticking to it usually boil down to: it is very expensive to scrap a huge code base and the fact that the developers already know the language, makes it cheaper to use than other languages.

Brian Rasmussen
When down voting please leave a comment. Thanks.
Brian Rasmussen
+22  A: 

I think that it depends on where you come from. When starting out as a programmer, I think that VB might be easier to read than C# for instance, since it relies more on words than symbols, which makes it easier to take in for regular people.

I was a VB programmer for many years and when .NET came I still worked in VB.NET for the first couple of years (didn't really see the point with C#). Now I have a few years of C# behind me and I sometimes find that VB.NET code takes a bit longer for me to "decode" than C# code does. Possibly because it relies more on words than symbols for some contructs...

Fredrik Mörk
You are describing my situation exactly as well.
Ruben
Same here - VB.NET code is full of "noise" when you look at it from a C-style syntax perspective. No offense to any VB-developers. Just the way it feels when you go from C# to VB.
Glytzhkof
agreed, I cannot stand VB.NET - the syntax is like a story... and yes I have had to use it constantly for months, it drove me crazy, I love C# syntax.
Dal
A: 

It would be hard to argue that it is any more-or-less "error-prone" than any other language. I also doubt the point re "vast majority of commercial MS web"; from what I've seen, C# is by far taking the lead for .NET development (with .NET being the flagship tool in the MS stack for things that aren't device drivers etc).

Marc Gravell
A: 

VB is very verbose and easy yo get used to as compared to C# which is case sensitive. For a novice programmer its the best starting point.

chugh97
+2  A: 

VB.NET is easier to learn, you are right, and it's easier overall than C#, in my opinion. It's the first point why VB is so popular. Another one, and the biggest point, I think, is that there is a huge conmunity of developers who worked with VB 6 and older verisons of this language and it's easier for them to develop applications with VB.net than to learn a new language.

iburlakov
+2  A: 

I work in an environment where we use both. We have switched to C# in favor of classic ASP and VB. In my opinion there are no deal breakers between the languages. For most projects you can do the same work with both languages. Now I do share your view on error prone and I also find VB to be cluttered (for no reason).

As others has mentioned, VB is very simple and historically you could build projects very fast. This lived on in web development (which is fast developed), but I think when people realize that C# is just as fast developed, VB will fade out. Another reason I think it will fade out is that everything else you code in (CSS, JavaScript) when making web applications looks more like C# than VB, so it makes sense to use C#, even for beginners.

miccet
+15  A: 

Below I've just copied my answer to another thread:

I develop in both VB and C# on a regular basis, most of my money-making has involved C#. Personally, I prefer VB for most (but not all … lambdas!) work. I can't really name any hard advantages apart from those outlined by Jon. Actually, Herfried has collected a few on his web site (in German!) but they are rather technical.

The thing that really bugs me about all C-related language is the stupid syntax. This is purely cultural but as someone who does most of his professional work in C++, and being quite proficient at it, I still absolutely hate the syntax. And not just C++' cute little quirks. No, the whole package. Why braces? Why semicolons (perhaps the stupidest decision in all of programming history)? Why the stupid C-style cast syntax? Why is there no keyword for variable declaration (actually, this is the stupidest decision)?

There are just so many things that really make me sad and angry. VB is no saint, its language has huge drawbacks. But nothing compared to what I've said above.

I realize that most of these statements need justification but I put forward that this is only because we have become so used to them. Additionally, here isn't the right place. Suffice to say that C#'s syntax, while being its main advantage over VB, is also its main disadvantage.

I don't prefer VB because of the My namespace, I don't prefer it because of XML literals, I don't prefer it because of weak typing, I don't prefer it because of optional parameters, or because of the much better switch statement. No, I prefer it because of the syntax.


That said, I've got to admit that VB becomes more and more encumbered by its syntax. The latest hype seems to be Linq queries parametrized with lambda functions and I readily admit that this makes many things simpler. Unfortunately, VB's syntax for lambdas is simply too cumbersome to compete with C#. Just consider how bloated a call to Parallel.For looks like in VB – compared to C#, where it looks natural. IMHO, the VB design team has gone in the wrong direction here, favouring conservative consistency over readability.


To answer your subjective accusation:

To me, Visual Basic seems clumsy, ugly, error-prone, and difficult to read.

You're certainly entitled to think so but as Marc has said below, you'll find it difficult to argue this objectively. I definitely can cite a number of C syntax elements which are objectively more error-prone than anything existing in VB. In fact, VB syntax has been developed to prevent such sitations explicitly.

“Clumsy, ugly … and difficult to read” are all qualifiers that can be tagged on to nearly all languages that you're unfamiliar with. Simply put: the uglyness is a direct consequence of your unfamiliarity to the language.

Knowing a language well means recognizing patterns in code. Well-written code will by virtuel of practice appear elegant, while bad (slow, error-prone) code will appear ugly. It's as simple as that.


One last remark: The articles cited by you contain several inaccuracies and outdated information. As sole justification for a highly subjective and emotional discussion they aren't very well suited.

Konrad Rudolph
When it comes to syntax, ruby wins hands down over VB. And its syntax doesn't look like C at all.
Blake Pettersson
Blake: yes, full points for Ruby. Finally a language doing it right. Python also scores highly with me. Still, I'm partially dissatisfied by all existing syntaxes.
Konrad Rudolph
+1 for "I prefer it because of the syntax." and for the semicolons bit. Having said that i like FluentInterfaces, and they just look better in C# because of the semicolons.
Pondidum
@Andy: fluent interfaces look better because C# allows line breaks inside statements! And here comes the good news: VB allows that, starting with the next version (now in beta).
Konrad Rudolph
@konrad, thats what i was getting at :). I also didn't know about the 'good news', looking forward to it :)
Pondidum
Ruby sucks :P ... now that I have that out of the way... the real reason for the majoy syntax differences between the keyword based the braces comes down to the easy of writing the parser. I used to be a huge VB (BASIC in general) fan but since I have moved to C# I find it much easier and faster to work in.
Matthew Whited
Why braces? Because they visually demarcate a block of code, if used properly. Yes, I realize indentation in VB does this too, but braces do this with greater clarity IMO. Semicolons make things easier for the compiler (just ask the VB compiler team about this). I find casting in C# highly intuitive and compact. And there *is* a variable declaration keyword: `var`
Robert Harvey
@Robert Harvey: 1) VB uses keywords to denote blocks, not indentation. So much for clarity. 2) About casting, C++ correctly chose to deprecate C-style casting a long time ago because it’s too visually inconspicuous (*not* a good thing; a cast should stand out, as it introduces changed semantics and potential weaknesses of the type usage). 3) No. I meant a syntactical hint preceding *every* declaration. `var int x` comes to mind. All other statements and blocks are introduced by dedicated keywords, why not declarations of variables and methods? Fie. Inconsistent and ugly.
Konrad Rudolph
@Konrad: 1) I meant *visual* demarcation. If you don't indent, it's difficult to tell where one block `begins` and another block `ends`. 2) You can use the `as` keyword in C#, if you don't like the usual method of casting. 3) Really unnecessary, and just extra noise. Note: I was a long time Pascal and Visual Basic programmer, so I understand the conventions, but C# seems to better fit my sensibilities.
Robert Harvey
@Robert Harvey: Unfortunately, I really have a hard time understanding your stance on 3) and I am honestly baffled how anyone can not see the advantage of a clear visual introduction to declarations. But then, languages like Python completely omit declarations which I find utterly repulsive. For me, both amount to deeply nested relative clauses that lack the verb at the very end.
Konrad Rudolph
@Konrad: I will admit it took a little getting used to at first. Part of the philosophical difference may be that *I no longer think of my programming language as a variant of English,* like I did when I used to program in VB. Moving to C# has made the programming language I use somewhat more symbolic (and succinct), without being too opaque. That symbolism has allowed me the mental freedom to think more conceptually about things like object orientation, message passing and lambdas.
Robert Harvey
@Robert Harvey: There’s a misunderstanding here. I didn’t say I wanted to write (similar to) English prose. My comparison to relative clauses was just an analogy. If you prefer, I could also say that a declaration without a leading keyword is like a bullet point item without the bullet point, or a quote without quotation marks. It’s missing a very important visual clue that makes scanning source code much faster.
Konrad Rudolph
+2  A: 

One advantage VB.NET has over C# (which will disappear with C# 4), is default and named parameters, a very nice thing to have when using VSTO.

Blake Pettersson
And, for that matter, "dynamic" - giving C# something comparable to VBs existing late/dispatch binding.
Marc Gravell
This so-called advantage has always been problematic to me - my read on that is that C# has overloads which are a safer way of achieving the same practical result.
annakata
the downside of overloads is they are more diffcult and confusing to maintain when you jsut want to set a few default values. You can end up with complex chains of overloads which compiler into nested method calls instead of being directly resolved to the method by the compiler.
Matthew Whited
A: 

VB/VB.NET belongs to RAD (Rapid Application Development) category. You can develop applications with just drag-drop controls from toolbox and less code.

NinethSense
You could say the same thing about the ASP.net + C# combo, no?
aaaidan
Yes, most Visual Studio based langauges do.
NinethSense
Well, at the age of VB (not .net) there was no C# etc. So VB was the only GREAT thing that time. Later VB users migrated to VB.NET. VB <> VB.NET anyway.
NinethSense
+9  A: 

VB can be used to make GUI's (pronounced gooey) to track IP addresses. This is often used in crime solving.

Rick J
I was just typing that...
Colin Pickard
http://stackoverflow.com/questions/177541
Colin Pickard
Wow.Just. Wow. That just made my day totally awesome.
aaaidan
omg wow...omg wow.
Jeremy Child
I'll never look at CSI the same way again.
Robert Harvey
+2  A: 

Well, I think you have to differentiate between classic VB and VB.NET.

I feel that VB.NET is not very popular, but Visual Basic "Classic" still is1 The reason is that it is VERY easy to create Windows app. Compare this to a Windows app in C++/Mfc, which was almost the only alternative at this time.

For the same reason Delphi was very popular once upon a time.

PhpFlashGuy
+5  A: 

Most of your argumentation against VB is only applicable to VB-Classic (second link) or based on faint or obsolete arguments

  • Even in VBC, you won't use GoSub ... Return etc.
  • What's wrong with static? C++ supports this too.
  • VB10 introduces implicit line continuation (you don't even need redundant semicola like C#)
  • The different cast functions exist in C++ and C# too. C#'s (object)(expr)-Cast-Syntax and object as type are even more confusing and inconsistent.
  • What's bad about with? You can create nested tree structures in a very intuive way which is not possible in C#.
  • Event-Handling in VB is much more elegant than in C#. You can introduce and handle events by a single keyword (WithEvents) without having to initialize delegates, eventhandler-procs etc. This makes GUI-programming in VB much more confortable and you don't need to generate event-code by the designer.
  • Optional parameters get introduced into the new C# - Hence they seem to be good.
  • VB.NET has both strict and shortcut-boolean operators.
  • You do check for syntax errors at compile time unless you run VB like a script-language.
  • End If is more helpful than just }. When having complex syntactical structures all the curly braces are just confusing whereas a concrete End ... assists you in determining which block hasn't been closed.
  • XML Literals - XML script is now a part of the code, fully support by intellisense.

All in all, there are just a few objective differences between VB.NET and C# apart from the syntax. E.G: GUI-designing is much more efficient in VB due to a better event system and a better IDE whereas e.g. algorithms can be expressed better in C# because the syntax is conciser.

The rest is just a question of your personal style. C-Style programmers feel comfortable with C#, VB (or maybe Pascal?)-Style programmers use VB.

But the word-based, more explicit VB-Syntax may be easier to read for beginners than all the symbols in C. Compare:

If (a < 15) Xor (b = 2) And Not Condition Then

to

if ((a < 15) ^ (b == 2) && !Condition())

This doesn't mean one language is better than another.

Edit : -----------------------------------------

To the argument VB would be error-prone. When you use Option Strict On it's as strict as C# but doesn't allow us to make such mistakes:

// VB would initialize with zero (C/C++ doesn't)
int countZeros;
// No confusion with loop bounds with For x = 1 To Length
for (int i = 1; i <= length; i++) {
    // Never confusing == with = 
    if (data[i] = 0) 
        countZeros++;
}
Dario
C# would give a compile error for not initializing countZeros (in local scope) and for assigning a value to data[i] in the if statement. I know you referenced c/c++ in your comment, but I believe the OP was comparing VB to C# :)
ebrown
For my opinion, VB10 beats C#10 big time!
Shimmy
+8  A: 

To me, Visual Basic seems clumsy, ugly, error-prone, and difficult to read.

To me, English seems clumsy, ugly, error-prone, and difficult to read, especially written by people who have poor grammar, poor spelling, reckless disregard for capitalization and punctuation, and no sense of how to spatially and mentally organize their thoughts.

It's not just that Visual Basic is difficult to read or clumsy because of the syntax of the language, but it's usually so because the programmer isn't really good at expressing one's own thoughts:

If blah = 10 Then If stuff = "foo" Then t = 1 + k: s = 42: dostuff21

Right, that's horrible. But it's not particularly difficult to write horrible code in other languages either. When written correctly, it would make a lot of sense even if the code is written in VB:

If SelectedType = 10 Then
    If UserName = "Foo" Then
        CurrentUsers = CurrentUsers + 1
        UserConnectionID = 42
        PerformUserOperation
    End If
End If

At least that's more readable and understandable. It's still BASIC. It really comes down to the ability of the programmer to clearly express his/her intentions by formatting code in a easy to read manner, using well-named identifiers, and paying attention to writing understandable code.

That said, I haven't touched Visual Basic much since the VB3 days, (hence the example with "old" syntax) but just because a language can be abused does not mean that it can't be used correctly to write fairly robust code. Sure, there may be some deficiencies, but approaches devised to getting around those problems also shows one programmer's skills over another.

(Indiscriminately spraying On Error Resume Next comes to mind as a not-so-good way to get around the deficiencies of the lack of exceptions in VB back in the pre .NET days.)

coobird
+2  A: 

As other have said, your aesthetic judgment over language syntax heavily depends on what you knew before. For a more than a decade, it looks like it has been a C-look-alike contest, with curly braces for "blocks", "->" for indirection ( perl, php ), parentheses for function call arguments, // for comments, and a semicolon at each end of line. Some people even thought that thanks to this 'pensée unique', if you know a language, you know them all, which is indeed ridiculous. But this instilled the idea among C++/Java people that's the only right syntax aesthetic and anything else is trying to clone COBOL.

A few years ago I switched to ruby, and now python, and I can't stand any more ugly semicolons, curly braces, and other garbage meaningless characters. The source code is meant to be read by humans. When I gave a try to visual studio, I chose VB over C#. I suspect some programmers to chose C# just to "look serious" with its java-like syntax, but come on, the very same features are there ... give your eyes a rest.

vincent
+1  A: 

I think part of the reason is because old asp programmers going into .NET as I have done are very familiar with VB already because VB script is the language ASP classic used for the most part. I felt it less time consuming writing in VB in .NET because I already knew how to speak VB. VB is also less of a crybaby than C#. I can read/write in both but I prefer VB because it's easy to make friends with if you're a new programmer.

Eric
+1  A: 

I personally like the way events are attached in vb.net with the 'handles' keyword ... The IDE /Visual Studio/ is also more responsive when dealing with VB and handles automatically most of the end-ifs and the like ... C# is of course much more consise and clean (IMHO, I've worked with both quite a bit)

Petar Kabashki
I prefer subscribing to events myself, not all the magical behind-the-scenes stuff that goes on with "Handles" and the VS designer.
Lucas
+2  A: 

Well, if you're talking about .NET, there's one really easy one I can think of:

VB.NET's editor in Visual Studio is much better at catching syntax errors than C#'s.

While C#'s editor got a huge improvement in VS2008 SP1, there are still some syntax errors the editor doesn't pick up on until you attempt to compile the program.

R. Bemrose
That background compilation is exactly what made editing large VB projects in VS2005 very very slow. In any case, that's what ReSharper is for ;)
Lucas
+1  A: 

Much of VB popularity originated in a time when VB's tooling was much more friendly than other available languages. The "classic" VB offered an easy way to build Windows applications without having to learn the guts of the Win32 API or bother with manual memory management. The barrier to entry for beginning programmers was much lower with VB than C++, so a lot of folks cut their teeth with VB.

These days, I think VB one advantage over C# is familiarity for those who have worked with VB through the years. Another advantage is that VB code is easy to read because of the tendency to use keywords instead of punctuation symbols. As someone who works in VB, Java, C, C#, and Python, I find that VB is the easiest language to jump back into when reviewing code that I wrote years ago. The syntax is more verbose, which often makes it easier to read code, and Visual Studio has always done a great job of formatting VB code to clean up the formatting as you type so that code is consistently formatted (regardless of the author's sloppiness).

As a side note, I find Python to be extremely easy to read & review for similar reasons. In Python, the formatting of code is enforced by the interpreter rather than the IDE, but the end result is the same. Python also favors keywords to punctuation, though arguably less so than VB.

gbc