# Option Strict and Option Explicit in VB.NET 2005

**URL:** <https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045>\
**Category:** blog\
**Created:** [August 4, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045 "2005-08-04T00:00:00Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![codinghorror](https://discourse.codinghorror.com/user_avatar/discourse.codinghorror.com/codinghorror/32/36371_2.png) [@codinghorror](https://discourse.codinghorror.com/u/codinghorror)\
**Post date:** [August 4, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/1 "2005-08-04T00:00:00Z")

</div>

I just noticed that [Option Explicit](http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vastmOptionExplicit.asp) is on by default for new VB solutions in Visual Studio .NET 2005:

* * *
This is a companion discussion topic for the original blog entry at: [http://www.codinghorror.com/blog/2005/08/option-strict-and-option-explicit-in-vbnet-2005.html](http://www.codinghorror.com/blog/2005/08/option-strict-and-option-explicit-in-vbnet-2005.html)

---

<div class="post-metadata">

**Author:** ![Paul\_Vick](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/p/d07c76/32.png) [@Paul\_Vick](https://discourse.codinghorror.com/u/Paul_Vick)\
**Post date:** [August 8, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/2 "2005-08-08T00:00:00Z")

</div>

???

Option Explicit Off has been the default in the product since VS 2002. I’m not sure how the people you work with have managed to turn it off, but I can ASSURE you that we’ve shipped it with it off, for exactly the reason you state - it was too easy for misspellings to create new variables.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://discourse.codinghorror.com/user_avatar/discourse.codinghorror.com/codinghorror/32/36371_2.png) [@codinghorror](https://discourse.codinghorror.com/u/codinghorror)\
**Post date:** [August 8, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/3 "2005-08-08T00:00:00Z")

</div>

Er-- you’re right. How did they manage to turn it off? I don’t know why I work(ed) with such knuckleheads. Let me update the post to reflect the correction.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://discourse.codinghorror.com/user_avatar/discourse.codinghorror.com/codinghorror/32/36371_2.png) [@codinghorror](https://discourse.codinghorror.com/u/codinghorror)\
**Post date:** [August 8, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/4 "2005-08-08T00:00:00Z")

</div>

Indeed, Explicit On is the default:

[http://support.microsoft.com/default.aspx?kbid=311329](http://support.microsoft.com/default.aspx?kbid=311329)

My current clean install of [VS.NET](http://VS.NET) 2003 doesn’t contain either Explicit or Strict, so it’s fully default (not specified), and Explicit is definitely enforced.

I’m pretty sure now I was thinking of Option Strict the whole time, which is not on by default. Mea culpa.

---

<div class="post-metadata">

**Author:** ![ScottS](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/s/ac8455/32.png) [@ScottS](https://discourse.codinghorror.com/u/ScottS)\
**Post date:** [August 8, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/5 "2005-08-08T00:00:00Z")

</div>

I agree with Mr. Appleman, strict should be on as well.

---

<div class="post-metadata">

**Author:** ![Paul\_Vick](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/p/d07c76/32.png) [@Paul\_Vick](https://discourse.codinghorror.com/u/Paul_Vick)\
**Post date:** [August 9, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/6 "2005-08-09T00:00:00Z")

</div>

No problem… As for the Option Strict thing, yeah, well, that’s something we get a lot of feedback on. We’ll just have to see… :-)

---

<div class="post-metadata">

**Author:** ![Thomas\_Eyde](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/t/8e7dd6/32.png) [@Thomas\_Eyde](https://discourse.codinghorror.com/u/Thomas_Eyde)\
**Post date:** [August 10, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/7 "2005-08-10T00:00:00Z")

</div>

If people want the stricter option, why don’t they just go for C#?

VB will always make a poor static language in my opinion. Keep its strengts, keep it dynamic, but make the dynamics both safer and faster.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://discourse.codinghorror.com/user_avatar/discourse.codinghorror.com/codinghorror/32/36371_2.png) [@codinghorror](https://discourse.codinghorror.com/u/codinghorror)\
**Post date:** [August 10, 2005, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/8 "2005-08-10T00:00:00Z")

</div>

Well.. considering the BCL TryParse sample I posted about today (granted, it’s from Oct 2003) had a static bug in it\*, I’m inclined to think it should be on by default.

It’s definitely USEFUL, but I think having it on all the time is a mistake. It should be turned off as necessary for interop and other situations that warrant its use (or if the developer prefers it).

Couldn’t this be done rather simply with project templates? Kind of like how [VS.NET](http://VS.NET) 2005 makes you select a development profile at install time (general, web, C#, etc). You could select “VB-loose” or “VB-strict”.

- The DoubleTryParseRoutine and DoubleParseRoutine methods used “Double” and “Decimal” datatypes instead of Double/Double! Clearly an intellisense error, but it wasn’t picked up because option strict was off..

---

<div class="post-metadata">

**Author:** ![Pxtl](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/p/b782af/32.png) [@Pxtl](https://discourse.codinghorror.com/u/Pxtl)\
**Post date:** [October 30, 2006, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/9 "2006-10-30T00:00:00Z")

</div>

Keep in mind the whole families of Python-like languages in which assignment is declaration and all typing is dynamic (everything’s Var) - and tons of useful apps have been made in these languages.

It takes practice to be that careful, but you can create much less verbose, more legible code if you do - plus it’s faster for quick one-offs.

Each approach has their place. Obviously if we’re talking about some rigorous financial enterprise application, all safety should be maximized - heck, even typecasts should be avoided in that sort of environment.

---

<div class="post-metadata">

**Author:** ![philico](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/p/ed8c4c/32.png) [@philico](https://discourse.codinghorror.com/u/philico)\
**Post date:** [February 1, 2007, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/10 "2007-02-01T00:00:00Z")

</div>

I like option strict off even if the compiler tries to guess. It will do it only once and if you are smart you will learn its habits. As a seasoned programmer, I coded well over a million lines of code throughout my professional career in VB6 and [VB.Net](http://VB.Net) and I see absolutely no problem with using this option. Like anything else in life, you just have to know what you are doing…

---

<div class="post-metadata">

**Author:** ![Jack72](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/j/3bc359/32.png) [@Jack72](https://discourse.codinghorror.com/u/Jack72)\
**Post date:** [April 28, 2008, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/11 "2008-04-28T00:00:00Z")

</div>

“It’s almost as bad as making a language case sensitive.”

What’s the argument against case sensitive languages..? It’s one of the reasons I love C#…

---

<div class="post-metadata">

**Author:** ![hobbit125](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/h/9d8465/32.png) [@hobbit125](https://discourse.codinghorror.com/u/hobbit125)\
**Post date:** [December 1, 2008, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/12 "2008-12-01T00:00:00Z")

</div>

Pxtl, typing in Python is dynamic, it is not weak. Everything is most certainly not a var. The following code will result in an error in python:

myVar = 12  
myVar = test

---

<div class="post-metadata">

**Author:** ![arth](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/a/ba8739/32.png) [@arth](https://discourse.codinghorror.com/u/arth)\
**Post date:** [December 31, 2008, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/13 "2008-12-31T00:00:00Z")

</div>

@hobbit125: Actually you will not get an error. This is because 12 and text are merely being bound to identifier myVar, not declaring a variable.

---

<div class="post-metadata">

**Author:** ![Ashok\_Babu](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/a/ce7236/32.png) [@Ashok\_Babu](https://discourse.codinghorror.com/u/Ashok_Babu)\
**Post date:** [March 5, 2009, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/14 "2009-03-05T00:00:00Z")

</div>

Thank u

---

<div class="post-metadata">

**Author:** ![Aaron](https://discourse.codinghorror.com/letter_avatar_proxy/v2/letter/a/e19adc/32.png) [@Aaron](https://discourse.codinghorror.com/u/Aaron)\
**Post date:** [February 6, 2010, 12:00am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/15 "2010-02-06T00:00:00Z")

</div>

I think it is ok for people to program with option strict turned off, I just hope they work for my competitors.

However, my complaint with Option Strict, is that it is not smart enough to NOT throw an error when you assign a subtype to a supertype.

Anyone know what possible purpose this serves?

I can only think of 2 possible reasons:

1. OOP was never intended to be used in [VB.net](http://VB.net).
2. The background compiler already slows things enough and walking the inheritance tree would make it worse.

I always program with it on because I want it to catch the obvious type problems, but wish it had the C# behavior of knowing you can assign a subtype foo to supertype fooBase without a cast.

---

<div class="post-metadata">

**Author:** ![codinghorror](https://discourse.codinghorror.com/user_avatar/discourse.codinghorror.com/codinghorror/32/36371_2.png) [@codinghorror](https://discourse.codinghorror.com/u/codinghorror)\
**Post date:** [January 7, 2025, 6:39am UTC](https://discourse.codinghorror.com/t/option-strict-and-option-explicit-in-vb-net-2005/1045/16 "2025-01-07T06:39:54Z")

</div>

Closed on January 7, 2025, 6:39am UTC


