Option Strict

lothos12345

Junior Contributor
Joined
May 2, 2002
Messages
294
Location
Texas
What are the benefits on having option strict on as opposed to turning it off? God knows its easier to develop an application with it off.
 
Leave it on. It's for your good health. It will trap errors during compile before they creep into your runtime and it will make your code stronger as you move forward. I think the type casting is probably the part most folks ***** about. If you leave it on for a month then you will know when you are casting something as you write the code. That way you have control over the cast and you know when it is happening.

I have had instances when working with COM objects and third party dlls where I had to turn it off because I need late binding. That's where you don't know the type of somthing until runtime, I believe.
 
It keeps your code tighter. It mostly helps me keep more aware of what is going on in my code. With option strict on, you can't make a narrowing conversion or cast without knowing it. With option strict off, people sometimes find themselves doing things like adding the numeric values of strings instead of concatenating them, or treating one type of object like another.

Sometimes it is a little extra typing because you have to explicitly code all narrowing conversions (Integer to byte, String to integer, Object to Control, etc.) but it also helps because you can't perform a cast or conversion that could potentially cause errors without knowing it.
 
Back
Top