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

Option Strict ON - WHY use it??

P: n/a
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
Share this Question
Share on Google+
9 Replies


P: n/a
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

P: n/a
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

P: n/a
Kelly,

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

Please do not multipost.

Cor
Jul 21 '05 #4

P: n/a
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

P: n/a
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

P: n/a

"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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.