Line Continuation and Visual Basic – More on C# vs. Visual Basic

Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

Line Continuation and Visual Basic – More on C# vs. Visual Basic

  • Comments 4

Clint has more on our Visual Basic vs. C# discussion on his blog today. Like Clint I am completely willing to let people choice the language of choice based on personal preference. One of the really great things about the .NET platform is how easily this is possible even when people on the same project choose different languages. And I do have a great deal of respect for C# and especially the people who designed it. I have a great deal of respect for Clint as well. But I still like Visual Basic better.

In his more recent post Clint takes on the line continuation character which is needed in Visual Basic for breaking a statement across multiple lines. I was tempted to just say “any statement that is too long for one line should be broken up into multiple statements” but that would be both too simplistic and unfair. Many statements just make more sense as one long statement and for readability breaking them across multiple lives can be a good idea. I just thank the stars that we are not limited to 80 character punch cards anymore. And so it may be that coming from a background that includes FORTRAN and other punch card programming I do not find a line continuation character much of a strain. I also think that it helps for internal documentation. It makes it much less likely, in my opinion, that extra code will be inadvertently inserted in the middle of a statement. Or that a multiple line statement will get inadvertently cut in the middle during a cut/paste operation.

And of course needing a line continuation character is an exceptional case with most statements fitting on one line nicely. At least I don’t need a semi-colon at the end of every statement so that the compiler doesn’t get confused.

Some additional good news is that the Visual Basic team is actually thinking about changing this for the next version of Visual Basic. Here in a blog post Paul Vick from the VB team talks about the issues and the possibilities. Will this happen? Hard to say but I think it would be great if it did.

I should address some of the comments on Clint’s last post while I’m at it. One commenter points out that in C# and other C family languages one can write something like:

if (condition) { dostuff }

and asks “try that in Visual Basic.” So I did. The following one line statement works just fine.

If (condition) Then dostuff()

in fact this line

If (condition) Then dostuff() : dostuff()  ‘ Did you know you could have multiple statements on a line with Visual Basic?

works the same as

if (condition) { dostuff(); dostuff(); }

Except of course in the C# version we have to remember the semi-colon after each call to dostuff (I created methods so I could be sure stuff compiled) and we use the key word “then” and the new statement coming colon on the VB code.

Another comment says that one thing programming languages should not be is verbose. Well verbosity may be in the eye of the beholder. As someone who used to do a bunch of programming in COBOL, Visual Basic seems down  right terse at times. But more to the point, brevity has its place but too much brevity can lead to confusion. There are reasons we eschew single character variables for most things after all. The right answer is a balance and I think Visual Basic has a good balance.

Note: See Visual Basic .NET and C# Side By Side for a look at some of the syntax of both.

  • I am on Team Alfred.  This is a great reason for why VB has survived so long.

    However, with respect Alfred, C# is a language that has a standard that everyone can see.  This gives the C# language alot of power.

  • I like the idea that .NET is allowing each developer to chose his "own best language". This is making a very big diffenrece against other choices like Java -> 1 language, no more, + tons of incompatible libs. With .NET there are tons of languages and 1 compatible lib...

    So I will not try convincing you "C# is far better than VB". It's of course what I'm thinking, but I respect your choice of VB. That said, VB syntax has always been horrible. If you're looking for a "well balanced" language, not to wordy and precise, I think Pascal is far better than VB. If Delphi had not been killed by Borland and all their errors, I'll certainly today hesitate between C# and Delphi.Net, but even with a gun on my temple, I'll never use VB :-)

    VB can be the language you're the most confortable with but it is not possible to say it is "better", "clearer" or anything else than C#.

    I'm not sure the choice to write the whole .NET framework using C# and not VB is just an "accident"...

  • Actually I do not believe that the whole .NET framework is written in C#. I think there is some C++ and some Visual Basic used as well. I know there is some Visual Basic being used in Visual Studio. I do believe that most of the reason that most of .NET is written in C# is because C# was the first language targetted to use it and also because compiler writers generally are more used to C-family languages. I wrote a compiler (a very small one I admit) in VAX BASIC many years ago BTW. It worked very well.

  • If you want Pascal on .NET, don't bother with Delphi - have a look at RemObjects Oxygene. Neat readable Pascalish syntax, and full coverage of .NET features, from lambdas to LINQ.

Page 1 of 1 (4 items)