VB.NET getting uglier and uglier

Note: this entry has moved.

All my programming life was tied to VB. I started with VB3, and finally became a master in VB6, where I was able to do ANYTHING the language would let me. Of course, there were MANY things that I couldn't do, and OOP and design patters were soooo cool that I really needed to get my hands dirty by doing real programming based on them, not just "bathreading". So I made inroads in Delphi and Java for some time.
Then came .NET, and MS gave me a new toy to spend my days (and many nights too) with. VB.NET and C# both provide extensive support for OO programming. Even when I still code and write books (see Amazon) in both languages, I prefer C#, because I find it cleaner and less convoluted. I believe over time, the mix of old VB keywords/syntax and new .NET constructs such as generics, is turning VB.NET into one of the ugliest languages EVER.

For example, I see (from the excelent article on MSDN) the VB format to construct generic types. It simply sucks:

Dim stack As Stack(Of Integer)

I assume if the constructor has parameters, those will go after the type specifier?! Compare that with the elegancy of C# 2.0

Stack&lt;int&gt; stack = new Stack&lt;int&gt;(); Constructor parameters go where you expect them to go, the type specifier is separated from the constructor call. It is simply perfect. For the VB version, I'd like it to be: Dim stack As Stack&lt;int&gt;<br>stack = new Stack&lt;int&gt;();<br><br>'Or<br>Dim stack as New Stack&lt;int&gt;()<br>'maybe <br>Dim stack as New Stack[int]()<br> Maybe the VB.NET team should find an Anders Hejlsberg for their design process...

Update: from the discussion with one of the VB language designers, where he praises YAVBK (Yet Another VB Keyword), I can only say "WTF?!". They're adding an IsNot operand?!?!?:!!?!?!?! From the example justifying it:

(instead of this): If Not x Is Nothing Then Console.WriteLine(”Has a value.”) (you will be able to write this): If x IsNot Nothing Then Console.WriteLine(”Has a value.”)
I wonder why on earth do VBers write code like that?! Look at the following equivalent (more readable) code: If x &lt;&gt; Nothing Then Console.WriteLine(”Has a value.”)<br>'Or<br>If x = Nothing Then Console.WriteLine("Doesn't have a value") It's FAR more readable and understandable than using that awful Is/IsNot test. It boils down to whether you want to teach VBers how to write good/maintanable/readable code or just give them new keywords to keep doing otherwise, but with less code.


  • I couldnt agree more. The VB team seems to do whatever is easiest for the compiler/parser not what makes the most sense for the developer. Attributes suck, the wishy washy nature of () on ctors and methods sucks. They really dont seem to care about the semantics of the language.

    One thing I found interesting was the initialization of Arrays is almost identical to C#: new String() {&quot;One&quot;, &quot;Two&quot;, &quot;Three&quot;}. Was they guy that designs the VB syntax at lunch the day they added that feature?

  • Negative comments like this will probaly not help your book sales. They only show your true character.

  • Hehe... you got me!

    However, I doubt any of the C#+VB authors can say honestly they prefer VB...

  • You know what? I kind of *like* how generics are implemented in VB.Net. It's pretty readable.

  • Yeah, Travis... I bet you would like having a constructor like the following:

    Dim stack As Stack(Of Integer, 10)

    I wonder how do you suppose your New() constructor would look like? Anyway, I AM also a VB programmer (from the point of view that I still do VB coding, for the books) and having both languages in my mind, I still prefer C#.

  • Still, I'll modify slightly the post to help my book sales ;)

  • Why not If x Is Something :-)

    I'm afraid to see if people will do something like this:

    If Not x IsNot Nothing *shock*

  • VB people loves their own verbosity!

    C# inherits elegance from C++ (and Java)

  • I'd add Delphi, Juan ;), after all, it Anders' son too.

  • You might claim to know VB, but any &quot;VB Developer&quot; knows that you can't compare reference types using &lt;&gt; and = operators. So, your example might be more readable, but it's definitely not valid.

  • Well, definitely you haven't evolved. In VB.NET you CAN do it. I tested it and it works. The example I showed was compiled and tested, and works just as expected.

    You're comparing against Nothing, not a specific reference type value...

    Now you see what I mean by &quot;teach VBers&quot;...

  • I'm pretty sure brian is right. You can't do = nothing in VB.Net except for with strings :)

    Sub Main()

    Dim s As String

    Dim h As Hashtable

    If s = Nothing Then


    End If

    If h = Nothing Then


    End If

    End Sub

    won't compile:

    Operator '=' is not defined for types 'System.Collections.Hashtable' and 'System.Collections.Hashtable'. Use 'Is' operator to compare two reference types.

    I pointed this behaviour out to Paul Vick a while ago, he said it was a good question and he'd get to it, he never did :) Basically, I was asking why have an IS operator (forget about IsNot)...this isn't a database! null = null!

  • I absolutely agree. I started with VB 1.0 all the way to VB 6. Then I did some Java and found out what I really liked. When it came time for .Net I wnet right for C# without a thought.

    I may just be a matter of taste, but VB just seems obnoxious to me. To each their own!

  • Karl, Brian, the problem here is the compiler, NOT the language. The operator = and &lt;&gt; is defined at the level of System.Object. Therefore, you should be able to use it with whichever descendant you have (ANY .NET type derives from it).

    It turns out that there's apparently a bug in the VB compiler, because the code I showed compiles for a string, but not for other types. However, it DOES work for Object types. So, if you cast your variables to Object, you will be able to use the cleaner code (not so cleaner now that you need to case, but well... it's still better/readable than Is/IsNot, IMO):

    Dim obj As Object

    Dim list As ArrayList

    'Object can be directly compared

    If obj &lt;&gt; Nothing Then


    End If

    If obj = Nothing Then


    End If

    'Other types need to be converted to Object !?!?!?!?!

    If CType(list, Object) &lt;&gt; Nothing Then


    End If

    If CType(list, Object) = Nothing Then


    End If

    I wonder how can they do such a thing... swallow an operator on the base class and show that as an error... my God...

  • (KZU: somehow, I lost your comment, Brian. As I don't want you to think I'm censoring you, here's the original text)

    &quot;As Greg Robinson already pointed out, you are showing your true character. You've insulted an entire genre of developers based on the tool they use.

    Anyway, back to the issue at hand...you MUST use the &amp;quot;Is&amp;quot; operator if you have &amp;quot;Option Strict On&amp;quot;. I know; that could open up a whole other bag of worms for you to play with! I'm not here defending VB.NET and it's syntax. I'm just here for the sake of arguing. :)&quot;

  • Hehe... Yup, we're all here for the sake of freely saying what we think :)

    BTW, I never INSULTED nobody. That's why the title of the post is about VB syntax, NOT VB developers.

    By looking for alternative solutions like the one I show, and NOT asking for yet another VB keyword, you are preserving the (already somewhat convoluted) language. In fact, if all VB developers were asking for the compiler to take into account equality and inequality comparison for object references (esencially asking to have what C# developers have), the result would be much cleaner/readable/maintainable. In the meantime, with &quot;Option Strict On&quot;, it's still preferable to write:

    Dim obj As Object

    Dim list As ArrayList

    If Not Object.Equals(obj, Nothing) Then


    End If

    If Object.Equals(obj, Nothing) Then


    End If

    If Not Object.Equals(list, Nothing) Then


    End If

    If Object.Equals(obj, Nothing) Then


    End If

  • BTW, that way you ensure that a regular non-VB .NET developer (i.e. JScript.NET, Deplhi.NET, MC++, etc) can clearly understand your code, instead of asking for them to know ALL the possible VB keywords and their meaning.

  • &quot;It's still preferable to write:

    If Not Object.Equals(obj, Nothing) Then...&quot;

    That's a joke, right? I fail to see how that's possibly cleaner than

    If Not list Is Nothing Then


    For crying out loud, it *looks like Java*, and those are semantics we *don't* want to copy.

    &lt;&gt; and = I would give you (and here's hoping Whidbey fixes them), but Object.Equals? Please.

  • Yup, I agree &lt;&gt; and = should be there, definitely. Maybe I was too optimistic about Object.Equals ;)

  • What I think is the strength of VB (as opposed to C++/C#/Java) is that it's syntax is much more like &quot;pseudo code&quot; that any normal person would use to describe an algorithm.

    For some reason, some people think you should start adding a bunch of non-aphabetical characters (like ={}[]!&amp;|) all over the place - which imho doesn't enhance the readability at all.

    I personally think:

    If x Is Nothing Then


    End If

    is a lot more easy-to-read than:

    if (x == null) {



    Regarding the generics, why on earth would:


    be more understandable than:

    Stack(Of Integer)

    The later one is almost like you would say it in english - which would have been even better.

  • In response to your reply in my guestbook.

    *ignoring your unnecessary sarcasm*

    &gt; natural language is FAR too ambiguous to be of any use in a programming language

    I agree, today's computers cannot parse natural language at a sufficient level, and even if they could, it would probably still be ambigious in some situations.

    This however is no excuse not to try to get a language that is as intuitive as possible. And I certainly don't think C#/Java is &quot;as intuitive as possible&quot;. Why should &amp;&amp; be more readable than And?

  • It seems to me that we actually are talking about different things. What I say I like is VB-style languages, i.e. langues that resemble to pseudo code. I don't say that VB is perfect in any way although I think it's pretty good. The more I think about it though, I believe you're right about the unnecessary keywords. IsNot is really superflous.

    Generics again: Yes, I believe &quot;Stack(Of Integer)&quot; is better than the C# alternative, since it's almost like &quot;A stack of integers&quot; (even though I personally would have liked &quot;Stack(...) Of Integer&quot; even better). I do agree with you however that paranthesis are used for too many different tasks.

    It seems that the VB design teem perhaps has done some not-so-good choices. I think it's a good thing though, that they dare to go their own way. For example, I really like that they didn't use the word &quot;static&quot; as it's used in C#/Java, but rather used the word &quot;shared&quot; which really tells something about what it does. I only wish the C# team have had the guts to do it too.

    You say that you don't know why the Microsoft.VisualBasic namespace is needed. Well, that namespace exists in order to make VB.NET backward compatible with VB6 and make it possible to upgrade VB6 projects without rewriting half of the code. For example, opening a file is (as you know) handled in very different ways in VB6 and VB.NET. I think it's a mistake to include that namespace automatically when starting on a new VB.NET project though as it encourages a bad programming style.

    And as you say, programming languages are absolutely a matter of taste - I suppose most things in life are.

    Thanks for an interesting discussion. =) If I was sounding rude at first, I apologize for that.

  • AndAlso and OrElse are, AFAIK, due entirely to a particularly noisy segment of VB6 devs who didn't want And and Or to change from non-short-circuiting to short-circuiting expressions for backwards compatibility reasons. (IMO, they should have just broken compatibility; AndAlso and OrElse are ugly little warts.) While backwards compat is an admirable goal -- and one Microsoft spends more time acheiving than most companies can possibly imagine -- in this case, I think anyone who wrote code depending on those two not short-circuiting deserves whatever they get. :-P

  • David Findley:&gt; The VB team seems to do whatever is easiest for the compiler/parser not what makes the most sense for the developer.

    This has always been my impression of the C family of programming languages, more so than VB. But YMMV.

    David Findley:&gt;Attributes suck

    Care to expand on that please? As your statement stands, it implies attributes suck in any .NET language which I am sure is not what you mean.

    David Findley:&gt;One thing I found interesting was the initialization of Arrays is almost identical to C#

    Ever thought that maybe the C# syntax was identical to the VB syntax? :)..(only an insider can say for sure what happened...)

  • Daniel:&gt; BTW, I never INSULTED nobody.

    That's pretty hard to swallow when you write things like:

    &quot;Well, definitely you haven't evolved&quot;


    &quot;Now you see what I mean by 'teach VBers'...&quot;

    both of which show an air of superiority on your part. In fact, the argument of not evolving can be leveled at you because you still think that VB arrays are 1-based, when that is not the case :-D

    This is your weblog and I am all for &quot;freedom of speech&quot;, but at the same time lets not forget simple professional courtesy...you did apologize in a later post, so its back to business as usual :)

  • Daniel:&gt; BTW, that way you ensure that a regular non-VB .NET developer (i.e. JScript.NET, Deplhi.NET, MC++, etc) can clearly understand your code, instead of asking for them to know ALL the possible VB keywords and their meaning.

    I see what you are trying to say, but there's more to understanding code written in another language, than just familiar library calls. Each language provides its own syntactical conveniences/conventions and sacrificing these &quot;just in case&quot; another non-language X programmer needs to read your code, is unwise at this syntactical level. Generics are coming to VB and C#, but try currently asking an MC++ programmer not to use the STL just so that a VB/C# programmer could understand their code... ;)

  • Eric :&gt;I think anyone who wrote code depending on those two not short-circuiting deserves whatever they get. :-P

    I quite like being able to control when they do/dont short circuit,as I have uses for both. If the compiler forced short-circuting, it would make some code less concise than it could be.

  • I'm sure you meant &quot;I could *not* care less&quot;, right? After all... if you could care less then it actually means something to you. If you couldn't care less, then it's the least important thing in the world to you.

    I'm just saying... with all this talk about programming languages maybe we should think about how we use our spoken one a bit, too ;-)

  • I come from scripting world and i'd love to see something like c# but not as strict, for example

    if (!object)

    This would check for null when object is not bool, and bools would default false etc.

    for strings that would check for null and &quot;&quot;, and if you wanted to check only for the other, you'd do it the old way.

  • If you want to talk ugly you will talk about languages that use semi colons and curly braces all over. Such things are clearly designed for the complier writers and not for programmers.

  • I must say working with both langauges I prefer c#, main reason is VB.NET encourages bad programming in the wrong hands, looks ugly and will never look as elegant as c/php/c#/javascript etc style semantics. I code in most languages and I must say, I can not stand the sight of VB.NET, if I can I will choose to code in c# these days, however, I am biased :) just don't like the way VB looks...

  • I can't believe I'm reading all this - my toy is better than yours......booohooooo

    Programming is a means to an end. Who gives a crap if someone prefers one language over another. Dotnet is about the framework. The language is just a matter of taste.

  • That's what we're talking about here... personal tastes when it comes to programming languages!

  • Yes, but why worry about what languages other people prefer? There is no 'God-of all' language.

    Learn one langauge, understand the framework, and your all set to learn the rest. Easy(?).....

  • I &quot;worry&quot; because I was a former VB lover. And I see it getting worse every time. That's all.

  • I worry because I have to fix up VB.NEWBS f**** sh** code. This is the main reason I hate VB, because I have spent the last 4 months fixing someone's VB fk up. but like I say, I am biased now due to this experience :)

  • I can agree with that :)

Comments have been disabled for this content.