473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Option Strict

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
12 1510
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
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
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
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
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
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
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
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
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
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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Microsoft News | last post by:
I have a project that was created all with Option Strict OFF. Works great, not a problem with it. But if I turn Option Strict ON then I get a LOT of errors. My question, should I even care...
11
by: Daylor | last post by:
hi. im using option strict on. im doing in ,from the simple reason ,to be warn when there are implict conversion like string to int ,int to string. BUT. the price ,(now i see ), is very bad....
8
by: Rich | last post by:
Hello, If I leave Option Strict Off I can use the following syntax to read data from a Lotus Notes application (a NotesViewEntry object represents a row of data from a Lotus Notes View - like a...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
15
by: guy | last post by:
when i first started using .net (beta 1) i came across option strict and thought hey this could be really good, and since then have always turned it on, most people here seem to agree that this is...
13
by: C. Moya | last post by:
I fully expected the lack of a way to set Option Strict globally to be fixed in SP1. I can't seem to figure out if it has been fixed or not. It still seems we have to add the declaration at the top...
1
by: Jerad Rose | last post by:
I believe this issue is specific to ASP.NET. Why does VB.NET (2.0) ignore the project-level setting for Option Strict? I have the setting turned on in web.config: <compilation debug="true"...
18
by: Poldie | last post by:
How do I turn it on? I'm using vb 2005 in visual studio 2005 sp1. In my web.config I have: <compilation debug="true" strict="true" /> In my Tools/Options/Projects and solutions/vb defaults...
8
by: Rory Becker | last post by:
A wise man once said: "Never put off until runtime what you can fix at compile time." Actually I think he said it about 10 minutes before I started this post. I am a firm believer, like the...
8
by: =?Utf-8?B?R3JlZw==?= | last post by:
We have an application in our office that has the Option Strict option set to off right now. I do understand it should be set to ON, but right now, I'm just going to continue with it this way since...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.