473,791 Members | 2,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1536
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******** ******@TK2MSFTN GP14.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.co m> wrote in message
news:Oe******** *****@TK2MSFTNG P09.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******** ******@TK2MSFTN GP14.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.co m> wrote in message
news:Oe******** *****@TK2MSFTNG P09.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******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP14.phx.gbl...
Thank you for your reply Sahil, would you mind explaining what
boxing/unboxing is?

"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:Oe******** *****@TK2MSFTNG P09.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******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP14.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.co m> wrote in message
news:Oe******** *****@TK2MSFTNG P09.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******** ******@TK2MSFTN GP14.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.co m> wrote in message
news:uA******** ******@TK2MSFTN GP15.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******** ******@TK2MSFTN GP14.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.co m> wrote in message
news:Oe******** *****@TK2MSFTNG P09.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******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP10.phx.gbl...
Thank you for your replies Sahil - Very helpful :)

"Sahil Malik" <co************ *****@nospam.co m> wrote in message
news:uA******** ******@TK2MSFTN GP15.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******** ******@TK2MSFTN GP14.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.co m> wrote in message
news:Oe******** *****@TK2MSFTNG P09.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******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP14.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2147
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 about Option Strict? What advantages do I get with Option Strict On? Does better type statement make my code run faster? If anyone knows THE ANSWERS! please fill me in. I have ideas and belief but I would once and for all like to know what the...
11
2119
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. if i have class CCar and interface ICar when im doing this : ICar = new CCar
8
1832
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 record in a sql Server view) .... Dim entry As Domino.NotesViewEntry Dim obj As Object str1 = entry.ColumnValues(0)
17
4494
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 binding. What should I do? Public Sub MyMnuHandler(ByVal sender As Object, ByVal e As System.EventArgs) If sender.checked = True Then sender.checked = False Else sender.checked = True
15
1550
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 a good thing. i have now been asked to debug a vb2005 web app for 3 weeks and there is no mention of option strict in it, (there are also no classes defined, just a couple of structures) everything is define as 'as object', data coming back...
13
2327
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 of each and every single code module. Am I missing something here? -- -C. Moya www.cmoya.com
1
3141
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" strict="true" explicit="true" urlLinePragmas="true"/> And also in the preferences:
18
2897
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 I have option strict on. In my .vb file I have:
8
2426
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 man in question, in "Option Strict On" by default. Actually I don't believe I have code where this is not the case.
8
3896
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 I do not have the time to fix everything to set it to ON. Anyway, my question is if its set to OFF why is it it keeps getting set back to ON, everytime we move the package from one machine to another. It's the Option Strict option specific to...
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9515
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10155
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7537
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5431
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.