Option Strict

  • Thread starter Thread starter Kenneth
  • Start date Start date
Kenneth said:
Should I have it ON or OFF

On for both performance and type safety; off for lazy type checking
(which can be useful very occasionally).
 
Hi Kenneth

I know I am going to regret this but here goes ...

In my personal opinion, Option Strict should always be ON. I have read a lot
of replies from people in these newsgroups that suggest that there are times
when it should/could be turned off. I have yet to be convinced that there is
such an occasion but I am open to other views, and examples.

HTH

Charles
[To everyone reading this, please feel free to suggest examples that
contradict me, and I will concede gracefully. But please, don't let's have a
slanging match that disappears off the end of my screen - it just makes my
head hurt]
 
Kenneth,
As Charles & Jon have stated, you should always use Option Strict On at the
top of each of your source files.

I normally include it at the top of each source file along with Option
Explicit On, so other developers know that this file requires that setting.
For if you attempt to rely on project settings, and copy the source file to
another project junior developers may get confused.

The only real time you need Option Strict Off is when you are using Late
Binding. If I need to Late Binding I would isolate it to one or two source
files in the far corner of my app. As Charles suggested, I have yet to need
to use Late Binding.

Word of caution, Late Binding uses reflection under the covers which can be
expensive at execution time. I normally dynamically load assemblies and
early bind to an interface. The objects that I dynamically load adhere to a
specific interface, allowing me to avoid Late Binding.

Hope this helps
Jay
 
Ditto, that it should be on ALL the time. If you are
having challenges with it being on, then that means
generally you don't have enough understanding about what
you are doing and that is all the more reason to leave it
on. All you are doing by leaving it off is pushing dirt
under the rug and which may appear later and cause more
problems and possible a lot of clean up.

Carol
 
I am a rookie on asp.net. I always use option strict on, but I am wonder how
you avoid late binding on say getting the command argument of a link button.
I have been using DirectCast because I get the late binding error without
it, but how else can I get the command argument of the button?
 
vMike,
If I am following your question, you avoid the error by using DirectCast. As
soon as you use DirectCast the compiler knows what type it is, as you just
told it, so it is able to early bind to the type you give in the DirectCast.

Hope this helps
Jay
 
Back
Top