Does Option Strict On add overhead?

  • Thread starter Thread starter Showjumper
  • Start date Start date
S

Showjumper

By turning Option Strict on, is there extra overhead? For example w/o it on
the following doesnt get flagged:
validxhtml.Attributes.Add("height", 22) but with it on the 22 is underlined
and the message is "Option Strict On disallows implicit conversions from
'Integer' to 'String'.". I then use validxhtml.Attributes.Add("height",
cstr(22)) and the blue squiggel goes away with strict on. By using cstr is
there extra overhead created?
 
The CStr conversion happens whether you have Option Strict on or not.
So no there isn't any overhead.
The main difference is that with Option Strict On you are forced to do such
conversions explicity instead of relying on VB to do them automatically for
you.
While this requires a bit of extra work, it is considered to be well worth
it to help prevent unexpected runtime errors.
These kinds of bugs can be notoriously difficult to flush out and can be
very expensive to fix if they are discovered after an app is deployed. This
is why most good developers will tell you to always turn Option Strict on.
 
Option Strict On causes no overhead.

In fact, it reduces the overhead caused by developers wondering why their
code didn't work, since it compiled ok.

In your example, why not use:

validxhtml.Attributes.Add("height", "22")
 
Back
Top