Option Strict

lothos12345

Well-known member
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. Its 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. Thats where you dont 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 cant 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 cant perform a cast or conversion that could potentially cause errors without knowing it.
 
Its also a lot easier to introduce subtle errors with it turned off. Turning it on requires you to be more explicit about your intentions.
 
Back
Top