By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

Option Strict

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.

Nov 18 '05 #2

P: n/a
Thank you for your reply Sahil, would you mind explaining what
boxing/unboxing is?

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:Oe*************@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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.


Nov 18 '05 #3

P: n/a
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" <co*****************@nospam.com> wrote in message
news:Oe*************@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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.


Nov 18 '05 #4

P: n/a
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" <to***********@makes-you-fat.com> wrote in message
news:ef**************@TK2MSFTNGP14.phx.gbl...
Thank you for your reply Sahil, would you mind explaining what
boxing/unboxing is?

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:Oe*************@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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.



Nov 18 '05 #5

P: n/a
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" <to***********@makes-you-fat.com> wrote in message
news:Op**************@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" <co*****************@nospam.com> wrote in message
news:Oe*************@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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.



Nov 18 '05 #6

P: n/a
Thank you for your replies Sahil - Very helpful :)

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:uA**************@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" <to***********@makes-you-fat.com> wrote in message
news:Op**************@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" <co*****************@nospam.com> wrote in message
news:Oe*************@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" <to***********@makes-you-fat.com> wrote in message
> news:ux**************@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.
>>
>>
>
>



Nov 18 '05 #7

P: n/a
You're welcome :)

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
"Simon Harris" <to***********@makes-you-fat.com> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
Thank you for your replies Sahil - Very helpful :)

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:uA**************@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" <to***********@makes-you-fat.com> wrote in message
news:Op**************@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" <co*****************@nospam.com> wrote in message
news:Oe*************@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" <to***********@makes-you-fat.com> wrote in message
> news:ux**************@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.
>>
>>
>
>



Nov 18 '05 #8

P: n/a
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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.

Nov 18 '05 #9

P: n/a
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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.

Nov 18 '05 #10

P: n/a
Great point. Let me give an example, from my real-life experience. I came to
work for this company a year and a half ago, and the guy that was directly
underneath me had taught himself VB.Net coming from a VB/ASP background. He
didn't use Option Strict. He had private fields that were integers exposed
via public properties that were strings. Imagine the difficulty tracing down
an issue with a non-integer string value being used to set the value of the
Integer field. Data types are important, moreso as the bigger and more
complex the app becomes. Making sure that your data types are correct not
only speeds up runtime performance, but can prevent some hard-to-identify
errors from happening as well.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Scott M." <s-***@nospam.nospam> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.


Nov 18 '05 #11

P: n/a
So all of us agree that Option Strict/Option Explicit are good things ..
then why the f*** doesn't everyone use it?

Atleast in Whidbey, they should make the default behavior to enforce those,
and overridable somehow. Overridable because there is still plenty of bad
code we need to live with.

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Oj**************@TK2MSFTNGP11.phx.gbl...
Great point. Let me give an example, from my real-life experience. I came to work for this company a year and a half ago, and the guy that was directly
underneath me had taught himself VB.Net coming from a VB/ASP background. He didn't use Option Strict. He had private fields that were integers exposed
via public properties that were strings. Imagine the difficulty tracing down an issue with a non-integer string value being used to set the value of the Integer field. Data types are important, moreso as the bigger and more
complex the app becomes. Making sure that your data types are correct not
only speeds up runtime performance, but can prevent some hard-to-identify
errors from happening as well.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Scott M." <s-***@nospam.nospam> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.



Nov 18 '05 #12

P: n/a
> Atleast in Whidbey, they should make the default behavior to enforce
those,
and overridable somehow. Overridable because there is still plenty of bad
code we need to live with.
You're preaching to the choir here, Sahil. I've been telling MS to turn it
ON by default for several years now.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Sahil Malik" <co*****************@nospam.com> wrote in message
news:O1*************@TK2MSFTNGP10.phx.gbl... So all of us agree that Option Strict/Option Explicit are good things ..
then why the f*** doesn't everyone use it?

Atleast in Whidbey, they should make the default behavior to enforce those, and overridable somehow. Overridable because there is still plenty of bad
code we need to live with.

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik

"Kevin Spencer" <ks******@takempis.com> wrote in message
news:Oj**************@TK2MSFTNGP11.phx.gbl...
Great point. Let me give an example, from my real-life experience. I came
to
work for this company a year and a half ago, and the guy that was directly underneath me had taught himself VB.Net coming from a VB/ASP background.
He
didn't use Option Strict. He had private fields that were integers

exposed via public properties that were strings. Imagine the difficulty tracing

down
an issue with a non-integer string value being used to set the value of

the
Integer field. Data types are important, moreso as the bigger and more
complex the app becomes. Making sure that your data types are correct not only speeds up runtime performance, but can prevent some hard-to-identify errors from happening as well.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Scott M." <s-***@nospam.nospam> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
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" <to***********@makes-you-fat.com> wrote in message
news:ux**************@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.
>



Nov 18 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.