Option Strict On and .NET for VB6 programmers

Yes! Option Strict is definitely a best practice with .Net. Emphasize that .Net is at it’s core a strongly typed platform, and will be until the DLR is more completely supported. With few exceptions, every Dim and Function should have an explicit type declared to go with it. Things like LINQ or Boo and JScript are the exceptions that prove the rule.

Here are some other things to point out. I’m sure you’re well aware of all this, but I’ve had to work with and maintain a lot of VB.Net code written by former VB6ers, and so this is something of a sore spot for me:

  • Don’t use the old string functions: LEN(), REPLACE(), TRIM(), etc
  • Hungarian warts are no longer recommended. oMyObject and sMyString are not kosher. Show them the reference in Microsoft’s Design Guidelines if they don’t believe you.
  • Make sure they learn about the new AndAlso/OrElse logical operators
  • PARAMETERIZED QUERIES and modern ADO.Net. Can’t emphasize that enough. They should never need to call CreateObject() again.
  • Scope works differently (and is more important) in .Net than it was in VB6. VB.Net still has modules, but they’re now more analogous to a static class. It’s important to understand how developing in a real object oriented environment be different, as opposed to the partial OOP support provided by VB6. There’s no good reason anymore to allow methods to run to ungodly lengths.
  • Make sure they get an introduction to Generics and Interfaces (including IEnumeralbe(Of T)), and learn why they should never use an ArrayList again.

I could keep going, but I’ll just point you to the Hidden Features of VB.Net Question to close out this rant.

Leave a Comment