Friday, March 16, 2012

Option Strict On

I am new to ASP .NET and I am taking it as an online class. I have a pretty simple question and it is more out of curiosity than anything. Our teacher always wants us to use Option Strict On at the very beginning of each of our web pages. Is that a standard setup or do you think our teacher wants us to use our brain more to work the code? Any feed back would be great. I have my ideas, I wanted to see what anyone else might think.
Thank you in advance for any insight.
Imkewel2simkewel2s--
Regarding this...

imkewel2s wrote:

...Our teacher always wants us to use Option Strict On at the very beginning of each of our web pages. Is that a standard setup or do you think our teacher wants us to use our brain more to work the code? Any feed back would be great. I have my ideas, I wanted to see what anyone else might think...


...your teacher is right.

For 99.9999% of the cases, "Option Strict On" should always be set in VB.NET.
As to why your teacher says this should be, you must ask your teacher.
As for other reasons why, in short...

MSDN wrote:

Visual Basic .NET generally allows implicit conversions of any data type to any other data type. Data loss can occur when the value of one data type is converted to a data type with less precision or smaller capacity, however, a run-time error message will occur if data will be lost in such a conversion. Option Strict ensures compile-time notification of these types of conversions so they may be avoided.


...that is, using Option Strict On helps one to avoid conversions that lose accuracy.
Doing so is certainly to be put on the list of "best practices" for VB.NET development.
Always turn it on. Always leave it on.
HTH.
Thank you.
--Mark Kamoski

if the option Strict is ON.... the application will force you to cast objects in not matched and i think the teacher asked for this ... so you can learn how to cast and convert objects explicitly not to rely on the platform itself to do that .......in that case that will affect the performace in the application so basically you willl avoid a bad habbits is programming

0 comments:

Post a Comment