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

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.