Hi All,
I've been advised to use option strict. I've tried to read up on this, all i
can find is that it...
"disallows implicit narrowing conversions"
This kinda makes sense - Means I have to explicitly cast or convert data
when comparing/setting two different data types right?
Is there any more to it than this? What are the benefits of using option
strict?
Regards,
Simon.Option Strict generally leads to better code.
How is that?
Well, for one, it prevents programmers from taking shortcuts and declaring
everything as object. Not only is the final code more intuitive to the end
user, you might prevent instances of boxing/unboxing not to happen.
Secondly, it allows you to catch more errors at compile time, i.e. type
mismatches, undeclared types etc. And an error caught at compile time is an
error saved at runtime.
- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:uxdp6OWsEHA.2808@.TK2MSFTNGP14.phx.gbl...
> Hi All,
> I've been advised to use option strict. I've tried to read up on this, all
i
> can find is that it...
> "disallows implicit narrowing conversions"
> This kinda makes sense - Means I have to explicitly cast or convert data
> when comparing/setting two different data types right?
> Is there any more to it than this? What are the benefits of using option
> strict?
> Regards,
> Simon.
>
Thank you for your reply Sahil, would you mind explaining what
boxing/unboxing is?
"Sahil Malik" <contactmethrumyblog@.nospam.com> wrote in message
news:OefR7SWsEHA.636@.TK2MSFTNGP09.phx.gbl...
> Option Strict generally leads to better code.
> How is that?
> Well, for one, it prevents programmers from taking shortcuts and declaring
> everything as object. Not only is the final code more intuitive to the end
> user, you might prevent instances of boxing/unboxing not to happen.
> Secondly, it allows you to catch more errors at compile time, i.e. type
> mismatches, undeclared types etc. And an error caught at compile time is
> an
> error saved at runtime.
> - Sahil Malik
> You can reach me thru my blog at
> http://www.dotnetjunkies.com/weblog/sahilmalik
>
> "Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
> news:uxdp6OWsEHA.2808@.TK2MSFTNGP14.phx.gbl...
> i
>
Also, I've been switching this on in VS.Net by right clicking the project >
Properties > Build
Are you aware of any way of switching this on permently in VS.Net?
Thanks again!
Simon.
"Sahil Malik" <contactmethrumyblog@.nospam.com> wrote in message
news:OefR7SWsEHA.636@.TK2MSFTNGP09.phx.gbl...
> Option Strict generally leads to better code.
> How is that?
> Well, for one, it prevents programmers from taking shortcuts and declaring
> everything as object. Not only is the final code more intuitive to the end
> user, you might prevent instances of boxing/unboxing not to happen.
> Secondly, it allows you to catch more errors at compile time, i.e. type
> mismatches, undeclared types etc. And an error caught at compile time is
> an
> error saved at runtime.
> - Sahil Malik
> You can reach me thru my blog at
> http://www.dotnetjunkies.com/weblog/sahilmalik
>
> "Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
> news:uxdp6OWsEHA.2808@.TK2MSFTNGP14.phx.gbl...
> i
>
Boxing and Unboxing - http://www.dotnetextreme.com/articles/cSharpBoxing.asp
:)
- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:efkKtVWsEHA.1156@.TK2MSFTNGP14.phx.gbl...
> Thank you for your reply Sahil, would you mind explaining what
> boxing/unboxing is?
> "Sahil Malik" <contactmethrumyblog@.nospam.com> wrote in message
> news:OefR7SWsEHA.636@.TK2MSFTNGP09.phx.gbl...
declaring
end
data
option
>
Yes there is .. go to Tools -> Options -> Projects -> VB -> .. whoaa u see
option strict/ option compare and option explicit .. more reading to do :)
- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:OpcEFXWsEHA.1156@.TK2MSFTNGP14.phx.gbl...
> Also, I've been switching this on in VS.Net by right clicking the project
> Properties > Build
> Are you aware of any way of switching this on permently in VS.Net?
> Thanks again!
> Simon.
> "Sahil Malik" <contactmethrumyblog@.nospam.com> wrote in message
> news:OefR7SWsEHA.636@.TK2MSFTNGP09.phx.gbl...
declaring
end
data
option
>
Thank you for your replies Sahil - Very helpful :)
"Sahil Malik" <contactmethrumyblog@.nospam.com> wrote in message
news:uAKcAdWsEHA.3872@.TK2MSFTNGP15.phx.gbl...
> Yes there is .. go to Tools -> Options -> Projects -> VB -> .. whoaa u see
> option strict/ option compare and option explicit .. more reading to do :)
> - Sahil Malik
> You can reach me thru my blog at
> http://www.dotnetjunkies.com/weblog/sahilmalik
>
> "Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
> news:OpcEFXWsEHA.1156@.TK2MSFTNGP14.phx.gbl...
> declaring
> end
> data
> option
>
You're welcome :)
- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:uu$breWsEHA.3556@.TK2MSFTNGP10.phx.gbl...
> Thank you for your replies Sahil - Very helpful :)
> "Sahil Malik" <contactmethrumyblog@.nospam.com> wrote in message
> news:uAKcAdWsEHA.3872@.TK2MSFTNGP15.phx.gbl...
see
:)
project
the
type
this,
>
Option Strict also "disallows late binding".
Late binding is when the application doesn't know until run time what an
object's true type is. This causes more overhead to your application and
opens the door to errors.
Not allowing late binding (and therefore enforcing early binding) means that
all objects must know their type at design time, because of this, the
IntelliSense in VS.NET tells you what class members are allowed on the
object.
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:uxdp6OWsEHA.2808@.TK2MSFTNGP14.phx.gbl...
> Hi All,
> I've been advised to use option strict. I've tried to read up on this, all
> i can find is that it...
> "disallows implicit narrowing conversions"
> This kinda makes sense - Means I have to explicitly cast or convert data
> when comparing/setting two different data types right?
> Is there any more to it than this? What are the benefits of using option
> strict?
> Regards,
> Simon.
>
The most important thing is that it turns potential runtime errors into
compile time errors.
Compile time errors are much easier and less expensive to fix, and they'll
never reach your users.
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Simon Harris" <too-much-spam@.makes-you-fat.com> wrote in message
news:uxdp6OWsEHA.2808@.TK2MSFTNGP14.phx.gbl...
> Hi All,
> I've been advised to use option strict. I've tried to read up on this, all
> i can find is that it...
> "disallows implicit narrowing conversions"
> This kinda makes sense - Means I have to explicitly cast or convert data
> when comparing/setting two different data types right?
> Is there any more to it than this? What are the benefits of using option
> strict?
> Regards,
> Simon.
>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment