Variant of Strict On and .NET for VB6 Programmers

I am preparing a Visual Basic 2005 class that targets Visual Basic 6 programmers porting to the .NET platform.

I would like some advice on whether to recommend them always turn on Option Strict or not.

I worked exclusively with C-style programming languages, mostly Java and C #, so for me explicit casting is what I always expect, what I need to do, as it was never an option.
However, I recognize the value of working with a language that has built-in support for late binding because it should not be overly explicit about the types of code that really save time. This is further confirmed by the popular distribution of dynamically typed languages , even on the .NET platform with the dynamic language Runtime.

With this in mind, if someone who is first approaching .NET for the first time using VB.NET and with a VB6 background should get an idea of ​​how to work with checking compile-time type because "best practice" in the CLR? Or is it "normal" to continue to take advantage of late binding?

+21
late-binding
Oct 21 '08 at 15:51
source share
8 answers

Yes! The Strict variant is definitely the best practice with .Net. Emphasize that .Net is the foundation of a highly typed platform and will continue to be until DLR is fully supported. With some exceptions, each Dim and Function must have an explicit type declared with it. The exceptions are LINQ or Boo and JScript rules.

Here is one more thing. I am sure that you are well aware of all this, but I had to work and maintain a lot of VB.Net code written by former VB6ers, and therefore this is something sick for me:

  • Do not use the old string functions: LEN() , REPLACE() , TRIM() , etc.
  • Hungarian warts are no longer recommended. oMyObject and sMyString are not kosher. Show them the link in Microsoft Design Guides if they don't believe you.
  • Make sure they learn about the new AndAlso / OrElse logical operators OrElse
  • PARAMETERIZED QUERIES and modern ADO.Net. I can not emphasize this. They will no longer need to call CreateObject() .
  • Scope works differently (and, more importantly) in .Net than in VB6. VB.Net still has modules, but now they are more like a static class. It is important to understand how to develop different in a real object-oriented environment, in contrast to the partial support for OOP provided by VB6. There is no good reason to allow methods to work with unholy lengths.
  • Make sure they get to know Generics and Interfaces (including IEnumeralbe(Of T) ) and find out why they should no longer use ArrayList .

I could keep going, but I just point you to the hidden possibilities of VB.Net Question to close this writing.

+24
Oct 21 '08 at 16:16
source share

Development time using the Strict option will significantly reduce debugging time.

+17
Oct 21 '08 at 15:54
source share

Option Strict obviously cannot replace good unit testing - but not vice versa. While unit testing can detect the same errors as Option Strict , this means that there are no errors in unit tests, that unit testing is often and early, etc.

Writing good unit tests is not always trivial and takes time. However, the compiler already implements some of the tests - in the form of type checking. At least it saves time. Most likely, it saves a lot of time and money (at least occasionally), because your tests were incorrect / did not cover all cases / forgot to take into account changes in the code.

To summarize, the correctness of your unit tests is not guaranteed. On the other hand, there is a strong guarantee that the type checking performed by the compiler is correct, or at least that its failures (uncontrolled array covariance, circular reference errors ...) are well known and well documented.

Another summary: Yes, Option Strict On is by far the best practice. In fact, I worked for many years in network communities like this. Whenever someone needed help with a code that clearly did not have Option Strict , we politely pointed out this and refused to provide further help until it was fixed. It saves so much time. Often after that the problem disappeared. This is somewhat similar to using the correct HTML when requesting help on the HTML support forum: invalid HTML may work, but again, it may not be the cause of the problems. Therefore, many professionals refuse to help.

+8
Oct 21 '08 at 16:11
source share

YES!!!!

In my opinion, both the developer and the teacher of the college YES.

It’s best to start with good habits from the very beginning, this will simplify the whole process, and Option Strict is one of those elements, which, in my opinion, is a NEEDED element.

added

There are literally many reasons that can be listed as to why, but the key is that this is the best practice, and when learning a new language is the key to learning these best practices from the start.

+5
Oct 21 '08 at 15:56
source share

Remember that there are two levels.

Option Explicit Option Strict

The main difference between the two is that Option Strict disables the automatic conversion of VB of different data types. You must explicitly use CType or another data conversion function to assign a variable to another type.

I use VB with 1.0, and although I see that this is a point of view, I think that Strict is overly jealous paritcularily when working with objects that implement or inherit different interfaces and classes.

First, I started with Strict, and if it starts to bother you, then go down to Explicit. But in no case both will not turn off, so this is crazy and excessive debugging time.

Over the years, with VB, I quite often use Double for all floating point variables. This way you avoid many problems with rounding and loss of precision. In VB6, I used long because it was a 32-bit integer, but Integer works just as well as it does in .NET, since it is Int32. I also recommend using Int32, Int16, etc. Instead of Integer, Long, etc., if Microsoft decides to override these keywords.

+4
Oct 21 '08 at 17:14
source share

I'm going to disagree with RS Conley (very unusual). My favorite VB6 gurus - Francesco Balena, Dan Appleman - all didn't like the automatic conversion of VB6 to favor Option Strict to .NET. Many experienced VB6 programmers know automatic conversion as "evil type coercion" ( pdf ) and will be happy to include Option Strict .

Sometimes it is better to use one small module without Option Strict to avoid a lot of complex reflection code. But this is the exception that proves the rule.

+3
Jun 09 '09 at 10:43
source share

Given Boehm’s opinion that fixing the problem that arose earlier in the development cycle consumes the least resources, I am a fan of every tool that helps developers β€œfix it” as early as possible. For this reason, I am a supporter of things like IntelliSense, which is both an improvement in efficiency and a tool that helps you implement working code earlier in the loop. (Work, but not necessarily correct.)

For this reason, I also support the use of the Strict option as a way to help avoid erroneous errors and subsequent corrections during development time.

+2
Apr 12 2018-10-12T00:
source share

If you are used to checking your types, you probably want the option to be a string. disabling it can have its advantages, but if your brain is not configured to detect errors when your compiler usually complains, I would say that it leaves it. I worked a lot at VB.Net, and I have to say that, despite the fact that most of the time I work with options that were disabled, I saw many situations where its inclusion would prevent a lot of errors.

0
Oct 21 '08 at 15:57
source share



All Articles