Stuck in a VB.NET Ghetto

At a recent trinug user group meeting, Richard Hale Shaw was going off on a tirade about how Visual Basic 6 was "the ultimate anti-pattern". I don't disagree. VB6 had some serious issues, many of which .NET resolves. Then he put a question to the audience: "What specific things about VB6 make it an anti-pattern?" I raised my hand and lazily pitched him a big fat underhand softball: Option Explicit. To which RHS responded, "what does that do? I'm not very familiar with VB6."


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2004/10/stuck-in-a-vbnet-ghetto.html

“You have to respect a man who isn’t about to let mere ignorance keep him from having an opinion.”

Amen to that.

Then he put a question to the audience: “What specific things about VB6 make it an anti-pattern?”

You would think that he would have avoided that question if he knew how unfamiliar he was.

So go into your underhanded pitch… why is Option Explicit in VB6 an anti-pattern?

I think you have to know Richard Hale Shaw to know just how “on character” that statement was. He is just a classic very opinionated person. Sometimes he even does have data to back up his opinions and in this case he was probably just gathering that data without as much work as it would have taken to actually use VB (he is a long time C++ bigot and proud of it).

Also, ReSharper (http://www.jetbrains.com/resharper/) is a godsend. It’s a VS.NET 2003 plug-in for C# that adds background compiling along with a host of other features that should be in any IDE worth a damn (refactoring, code generation, etc.). If there was something like ReSharper for VB.NET, I would consider using VB.NET more often.

I never use /* */ comment syntax in C# and I can’t imagine a good reason anyone would other than personal preference. It definitely shouldn’t be listed in “top ten” list of reasons not to use VB.NET when there are other much better reasons… tool support being the main one for me, there are a lot of other great tools like ReSharper that are C# only.

I currently maintain a code base written in both VB.NET and C# (really, don’t ask) and there is much more friction than I expected.

There is supposed to be a VB.NET version of ReSharper-- I saw a post from one of the JetBrains developers that indicated they were working on it.

Option Explicit (off) is pretty evil-- all variables “just work” without declaration. Leads to a lot of typo-style bugs…

Before VB.NET 2003, I hadn’t used VB since version 3, ten years ago. I was really surprised to see “option explicit” still in there!

Um a number of observations:

Firstly I think one problem we have is that VB.NET and VC#.NET programmers can do the same task the same way but typically they do think differently. This isn’t bad it just “is”. I don’t have a problem with functions not returning values. For some reason, when I code little details like my function achieving a point are on the top of my list. Maybe it’s the intellisense, the case-insensitivity, the With block, autoindentation or the CrLf logical line termination that frees up my mind to spin on those little matters.

In VB8 I’m actually annoyed by the background compiler telling me my variables aren’t used, I wouldn’t mind it on a build, but as soon as I declare a variable I have to hear about how I haven’t used it.

I agree, background compilation should be turn-offable. Secondly you should never have 31 projects with 1,000 classes each open at the same time, working on them, using project references. Friends don’t let friends develop Enterprise Applications by themselves. Seriously, get a team.

Multiline strings would be nice, I don’t remember seeing any C# syntax for that either though (or were you describing strings with next lines in them?) multiline comments, I’m sorry but I’ve never considered typing ’ a big enough hassel to complain, perhaps if I had to type // I’d be irritated. Middle-of-line comments, why would you use this?

As for unitialized variables, ValueTypes are preinitialized, I think you know this. Reference types are initialized to Nothing and I seem to remember that well enough. However, in VB (I assumed in C#) when you have a bug due to a null reference VS tends to open the code file and highlight the line and throw up a big box, so no, I don’t have problems tracking those down.

Your problem wasn’t that you moved to VB.NET, the problem was that you were a bunch of C# coders moving to VB.NET and even that’s not the greatest of excuses. I thought you guys were suppose to have all that natural discipline and hardcore 1337 5k!115.

In all fairness you have some legitimate concern about my language and I respect them as valid.

While I don’t often find myself spanning lines of code across 15 logical lines I suppose that’s an issue. However in terms of multi-line comments none of the code from Microsoft that I see uses them, I think the message is clear that to get good Enterprise level code you should only use \.

I don’t know if it was fixed or not but last I checked C# has no intellisense ability with respect to Enumerations, neither with setting/checking variable values or passing parameters to methods. This bothers me.

C# more literally reflects the Event model but I really like declaring events the VB way without the middle step.

So in C# do you guys have to declare a wrapper method to expose an interface member under an alternate name?

I always thought the purpose of ref arguments was to get out return values, leave it to C# to invent a near useless redundant argument passing mechanism (I know the counter-argument so don’t bother).

Damn I wish we had XML comments, you guys definately won out there.

Using is overkill. It’s nice when you don’t care about the exceptions that pop up and when you only have 1 object to track. Nested Using blocks are worse than nested With blocks. If you’re already using it’s not like you have to do that much work for Try/Catch/Finally (Type Try, hit Enter, most of the work is done now). The more variables you have to dispose of the less useful Using is. If you really want to streamline the process, Declare this somewhere global:

Friend Sub IDispose(ParamArray iDisposables as System.IDisposable())
If iDisposables Is Nothing Then Return

For Each iDisposable As System.IDisposable In iDisposables
If Not iDisposable Is Nothing Then iDisposable.Dispose()
Next
End Sub

yeah I know, I overloaded the identifier a lot and I don’t apologize for it, not like I have to look at it all the time. With a method like that you could Dispose of 100 objects in 1 line placed in your finally block.


Try

Finally
IDispose(fsIn, fsOut, myForm, someObject, moreObject, otherStuff, tooManyObjectsWithUnmanagedResourcesInThisMethod)
End Try

We just think differently. That’s why the two languages coexist - We’re not all the same.

“you guys”? I use VB! I think you might have me confused with the person whose post I quoted from Paul Vick’s post:

http://www.panopticoncentral.net/archive/2004/05/28/1085.aspx

While a few of the points are valid, as always the language you choose to develop with against the .NET framework has less to do with productivity than the overall talent of the developer. Inherently, one language will be easier to use for this functionality or that functionality, but come on its the same CLR. Its like arguing over whether chocolate or vanilla is better its just opinion. I get so tired of this discussion. Just think if each .NET developer who had argued about this had used that much time to learn the other language, or least parts there would be much less arguing. In closing it does the .NET community a great disservice, and is counter productive.

But chocolate IS vastly superior to vanilla in every way.

Just ran across this on the Web.

Jeff, you were there, I would have thought you’d have gotten your facts straight. My reply was, “what does that do? I’m not very familiar with that feature of VB6.” After you described it, I remembered it. If I recall, I even talked about why it’s a problem that a language even needs a feature like that.

Interestingly you used my indictment of VB6 to indict VB.NET; and yet my discussion had little to do with VB.NET per se.

So maybe you need to get your facts straight, Jeff.
Regards,
RHS

Where do VB.NET programmers come from? I know where C# programmers come from. They go to college and study computer science where they learn C, C++ and Java. From what I’ve seen, you get VB.NET programmers from VB Programmers who became VB Programmers because they were teaching themselves how to write software in the first place. Calling VB 6 code programming is like calling an MS Access user a Database Administrator.

People without CS degrees who get into VB.NET don’t have the same sophistication in their technique or depth of computer understanding, and the needs of these less sophisticated developers are reflected in crappier tools and the weaker constraints of the language. VB.NET programmers are expected to make some software but not realy commercial enterprise applications. I mean come on, if you want a programmer to write multi-threaded n-tier client/server applications where they have to manage thread contention over shared resources, optimize database access resources, program asynchronous IO calls, and understand how the CPU processes context switching to make good solid stable robust scalable code, would you want the typical VB.NET (formerly VB self taught) programmer or the typical C# (formerly C++, Java, C, Lisp) programmer? Who would you rather do your multi-million dollar big software development project?

By the way, I found this thread by googling for “VB.NET SUCKS” (I guess that means I’m not un-biased).

AND YES, CHOCOLATE IS BETTER THAN VANILLA!

Ok I look forward to your backlash of comments. Flame on VB guys I got it comming to me…

To do a multiline comment:

select the block of code then,
ctrl + k then ctrl + c

to remove multiline comment:

select the block of code then,
ctrl + k then ctrl + u

No flame David B. You’re just wrong because you’re overgeneralizing.

Some of us are well trained and experienced in C/C++ , but our companies dictate that we program in VB.NET. With what they’re paying me, I’ll program in VB.NET with a big smile on my face, and use C/C++ on my linux machine at home.

BTW, I’ve done “multi-threaded n-tier client/server applications where they have to manage thread contention over shared resources, optimize database access resources, program asynchronous IO calls” just fine in VB.NET thank you.

spacca: Also, don’t forget the GUI way too. Select the code block, click the “Comment text out the selected lines” button. And to reverse it, click the “Uncomment the selected lines” button.

Note: This feature, along with the keyboard shortcuts, have been in the VB IDE since (I think) VB5.

David B.: One of the points you are missing is that if you are going to hang a picture on your wall, which would you use to get the job done quickly: A 16 oz. hammer or a 5 pound sledgehammer? (Something to think about: Holes in the wall larger than your fist)

Most people know now (after more than a decade of VB’s existence) that VB (VB3-6, VB.NET) has always been considered a RAD language. If you don’t know what RAD is Google “VB RAD”. And, yes there is a right way and a wrong way to implement RAD. The same as there is a right way and wrong way to hang a picture on your wall.

Basically, choose the right tool for the job. C/C++/Java are all good languages (Java leaves some things to be desired…) as are VB/VB.NET and C#. One thing to always remember, which is going to get the job done quicker? I’ll bet you that I can code a database app with full transactions and validation along with a useful and functional GUI quicker in VB.NET than you can in C/C++/Java. I’ve been there on the C++ front with a DB app and it took me longer to declare and implement all the necessary ADO calls than in the similar app created in VB.

On the same note, I wouldn’t use VB for low level functionality that C can accomplish quickly and efficiently.

Just for fun, code a full accounting system in assembly… :wink:

Heh… Try this in visual studio:

1.) Create a new asp.net web application (vb.net). Import System.Data.SqlClient.
2.) Create a class library in the same solution.
3.) Add to that class library a function with 31 input parameters
4.) put a button on the webform1.aspx page (or whatever page you have set as your start page for debugging). Create an event handler for the button.
5.) In the event handler declare a SqlParameter and assign it a value. Also put in a call to your function with 31 input parameters. Put a breakpoint anywhere in the function.
6.) Start the solution in debug mode. Now, click on the button and try to reference the value of the SqlParameter in the immediate window; you’ll get something like this:

? paramApplication_id.Value
error: cannot obtain value
paramApplication_id.Value = 1
System Error H80131313

To my knowledge this issue popped up randomly in the past week, perhaps Microsoft put out a patch that screwed up memory handling. Anyway, if you run into this problem, be aware that it’s the number of input parameters you’re passing to the function that’s causing it. I spent about 5 hours trying to track this down, hopefully you won’t be so lucky…

Well… I think that settles that. I think it’s quite obvious by now, and that everyone is very much aware that VB.Net is a much better product. Bravo Microsoft. BRAVO!

To dave b, i agree with Mako. I too am in the same situation where I have been told to use VB.Net rather than C#.NET . Your comments are childish. My college (pre university) course taught VB6 as the primary language and I taught myself C.

When you say in vb.net your project will take 2 to 3 times longer i agree, i have been working on a project which i would probobly have finished by now and be selling, but because of the ‘advantages’ of vb.net i am so far behind its unreal, like nearly 8 months behind, and i would just scrap what i have done and recode the whole thing in vb6 again, but i have something like 35 forms, and 10,000’s of lines of code which simply wont work if you copy it back into vb6, i dont really have much choice then to stick with it.

another thing i hate about vb.net is it is so fussy and buggy, for example if i copy the code (which works) from my desktop pc to my laptop , so i can work on it when im not at home, the program just doesnt work, and im talking about things like, closing one form and opening another straight afterwards. vb6…simple and easy. vb.net, it doesnt work if i run it on my laptop, but it works fine on my desktop PC, ?!?!?!!?!?!?!!?!?! wtf? they are both 32bit systems, the only difference is my laptop is just a bit faster. why would the code not work. and if i compile the program on my desktop pc and run it on the laptop it works, if i compile it on my laptop, it doesnt work, the program just crashes.

christ and i have had 100’s of other problems, including control arrays, that was so easy and usefull in vb6, but nooooooo. M$ scraped it and made their own code based way to do it, which i have never gotten to work.

i thought it would be a good idea to finally catch upto the ‘latest and greatest’ technology and stick with vb.net. i was SO wrong. just stick to the old stuff, it works fine.

i hate vb.net and i hope they fix stupid problems like this soon, you would have thought with all their money and resources microsoft would produce a decent bit of software.