473,386 Members | 1,720 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,386 software developers and data experts.

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 2112
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.net> wrote in message
news:uk**************@TK2MSFTNGP12.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.com> wrote in message
news:lg********************************@4ax.com...
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.net> wrote in message
news:uk**************@TK2MSFTNGP12.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.netNoSpamM> wrote
in message news:4D**********************************@microsof t.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
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...
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...

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.