473,732 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Option Strict ON - WHY use it??

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 difference is.

Thank in advance

Clyde W.
Jul 21 '05 #1
9 2145
Answers inline

"Microsoft News" wrote:
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?
Becaue you don't like sloppy code.
What advantages do I get with Option Strict On?
The primary one is forcing explicit coding standards.
Does better type statement make my code run faster?
NO. But, Option Strict can get rid of some really annoying logic errors
(syntax errors blow up, logic errors introduce bad data to application,
possibly even messing up your database).

OK, I will take that back. There are times when Option Strict can improve
performance, as well, by taking away certain VB.NET crutches.
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 difference is.


Overall, explicit coding is better, both for maintenance and ensuring your
code runs as expected. In 90% + of scenarios, turing Option Strict OFF is
fine. It is that small percent where it kills you. In most cases, bad
programming practice causes code to blow up when you turn Option Strict ON.
It is better to conquer those potential problems than leave them and turn it
back OFF. This is much like treating WARNINGS as ERRORS. While code works
fine when they are there, there is a small percentage of code that either
bombs, or worse, corrupts data when WARNINGS are left in. Best to erradicate
than take chances. Just my two cents.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
Jul 21 '05 #2
With Deft Fingers, "Cowboy (Gregory A. Beamer) - MVP" wrote:
It is better to conquer those potential problems than leave them and turn it
back OFF. This is much like treating WARNINGS as ERRORS. While code works
fine when they are there, there is a small percentage of code that either
bombs, or worse, corrupts data when WARNINGS are left in. Best to erradicate
than take chances. Just my two cents.


Interesting... I've too have always wondered about it. But my question (which
really doesn't need to be answered) is "why then NOT have it as a 'default' ON
and force all of us to clean UP our code?

If we "had" to write better code, then we would... but if we are not 'forced'
to... we write 'just to get by' code (and I am horribly guilty of that) (:

Regards,

Bruce
Jul 21 '05 #3
Kelly,

You have more answers including mine in the dotnet language.vb newsgroup.

Please do not multipost.

Cor
Jul 21 '05 #4
Bruce,

Probably it is not by default "on" because of the large part of VB6
programmers which are migrating, who will probably become crazy when they
have to do the casting as well.

I have it by default "on" in the Options and have seen not one situation
where I have to set it to "of".

However it is easier trying with option strict of, because sometimes you
have to cast more times with option strict on. (By instance when you are
trying something with MSHTML you can better start doing it with option
strict of and set the casting than later and put option strict on)

Just my thought,

Cor
Jul 21 '05 #5
With Deft Fingers, "Cor Ligthert" <no************ @planet.nl> wrote:
I have it by default "on" in the Options and have seen not one situation
where I have to set it to "of".
Huh! I didn't even see that in Options! I'll go look (kind of thought it was
funny that you couldn't see it one way or the other).
have to cast more times with option strict on. (By instance when you are
trying something with MSHTML you can better start doing it with option
strict of and set the casting than later and put option strict on)


Thanks Cor!

Bruce
Jul 21 '05 #6

"Microsoft News" <Na**@coxinet.n et> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...
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 difference is.

Thank in advance

Clyde W.

This is from the .net sdk

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.

Mike
Jul 21 '05 #7
It should be on by default - that's one of the main things that people take
pot shots at VB.NET about

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Mr. B" <Us**@NoWhere.c om> wrote in message
news:lg******** *************** *********@4ax.c om...
With Deft Fingers, "Cowboy (Gregory A. Beamer) - MVP" wrote:
It is better to conquer those potential problems than leave them and turn itback OFF. This is much like treating WARNINGS as ERRORS. While code works
fine when they are there, there is a small percentage of code that either
bombs, or worse, corrupts data when WARNINGS are left in. Best to erradicatethan take chances. Just my two cents.
Interesting... I've too have always wondered about it. But my question

(which really doesn't need to be answered) is "why then NOT have it as a 'default' ON and force all of us to clean UP our code?

If we "had" to write better code, then we would... but if we are not 'forced' to... we write 'just to get by' code (and I am horribly guilty of that) (:

Regards,

Bruce

Jul 21 '05 #8
The fact that you 'get all these errors' tells you that your code has
issues. Go check out the DailyWTF for proof. Almost all of the REALLY bad
VB.NET code can only be as bad as it is b/c Option Strict is off

Your code will run a lot faster with Option Strict on and you'll have a
safety net to protect you from a lot of really bad but easy to make
mistakes.

Moreoever by using strong typing - you get intellisense support.

Option Strict Off = Option Slow ON!

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Microsoft News" <Na**@coxinet.n et> wrote in message
news:uk******** ******@TK2MSFTN GP12.phx.gbl...
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 difference is.

Thank in advance

Clyde W.

Jul 21 '05 #9
Greg:

Not trying to nitpick but There's a big performance issue with leaving
option strict off.

As Dan Appleman has pointed out - Option Strict Off = Option Slow On.

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Cowboy (Gregory A. Beamer) - MVP" <No************ @comcast.netNoS pamM> wrote
in message news:4D******** *************** ***********@mic rosoft.com...
Answers inline

"Microsoft News" wrote:
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?
Becaue you don't like sloppy code.
What advantages do I get with Option Strict On?


The primary one is forcing explicit coding standards.
Does better type statement make my code run faster?


NO. But, Option Strict can get rid of some really annoying logic errors
(syntax errors blow up, logic errors introduce bad data to application,
possibly even messing up your database).

OK, I will take that back. There are times when Option Strict can improve
performance, as well, by taking away certain VB.NET crutches.
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 difference is.


Overall, explicit coding is better, both for maintenance and ensuring your
code runs as expected. In 90% + of scenarios, turing Option Strict OFF is
fine. It is that small percent where it kills you. In most cases, bad
programming practice causes code to blow up when you turn Option Strict

ON. It is better to conquer those potential problems than leave them and turn it back OFF. This is much like treating WARNINGS as ERRORS. While code works
fine when they are there, there is a small percentage of code that either
bombs, or worse, corrupts data when WARNINGS are left in. Best to erradicate than take chances. Just my two cents.
---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************

Jul 21 '05 #10

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

Similar topics

11
2115
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
1828
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
4487
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
9
325
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...
13
2324
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
3140
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
2896
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
2425
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
3895
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
8774
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
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
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...
0
9181
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
8186
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...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
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
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.