8 Replies - 7609 Views - Last Post: 24 June 2013 - 06:06 PM

#1 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Not Using Option Strict

Posted 22 May 2013 - 09:50 AM

So, I've noticed that when people are having problems with their programs, one of the first if not the first suggestion unanimously offered is to turn on Option Strict. Using Strict will generally highlight an error in data types or some such that experienced programmers would already recognize, and the consensus is that in all cases, Option Strict on is a pretty darn good idea.

So, my question is:

Why isn't Strict on by default in Microsoft's IDE? What are the reasons for NOT using Option Strict? Are there cases where a person can be following proper programming guidelines and be unable to use Strict? I guess my real question is:

Why is it an Option in the first place?

Is This A Good Question/Topic? 0
  • +

Replies To: Not Using Option Strict

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9076
  • View blog
  • Posts: 34,119
  • Joined: 12-June 08

Re: Not Using Option Strict

Posted 22 May 2013 - 09:56 AM

... foremost because Visual Studios is not synonymous with VB.NET, right? You can use it with other languages, and sometimes I need to run the edge of late bindings, or weak typing, when mucking with some shady objects.

Though when starting out programming, or with greenhorn questions it damn awesome to have on. Eventually greenhorns mature and the need is less imperative.
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is online

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Not Using Option Strict

Posted 22 May 2013 - 10:17 AM

I pretty much feel like it was implemented it when they implemented Default Instances of forms and turned it off so that it was easier for people to move from vb6 to vb.net and not drastically change their style of coding.

As if to say, come on vb6ers, you can write code the way you're use to now.

If you were to install the first version of vb.net you would be surprised by the number of people today that couldn't get code to work with it.

I will say that the tagline in my signature is based on truth. I realized very quickly that I wasn't writing code, I was putting things in a syntax and letting the compiler figure out what it thought I was trying to do.

Option strict gave me a lot more insight into my code.
Was This Post Helpful? 3
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: Not Using Option Strict

Posted 22 May 2013 - 02:11 PM

22 years of inert of legacy code.

You need Option Strict Off to handle Dynamic programming, since vb.net doesn't have C#'s dynamic keyword.

But you can sanitize the affects via partial classes (the code is spread across multiple files).
Was This Post Helpful? 1
  • +
  • -

#5 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: Not Using Option Strict

Posted 22 May 2013 - 04:47 PM

View Postmodi123_1, on 22 May 2013 - 04:56 PM, said:

... foremost because Visual Studios is not synonymous with VB.NET, right? You can use it with other languages, and sometimes I need to run the edge of late bindings, or weak typing, when mucking with some shady objects.

Though when starting out programming, or with greenhorn questions it damn awesome to have on. Eventually greenhorns mature and the need is less imperative.


Ha, that's so funny, the only time I've deliberately turned off Strict was when I was mucking about with a dodgy object. In fact, I didn't even turn it off, I just disabled the Late Binding warning.
Was This Post Helpful? 0
  • +
  • -

#6 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Not Using Option Strict

Posted 23 May 2013 - 03:45 AM

It came out handy turning Strict Off in this tutorial. Take a look at the 2nd block of code in last spoiler, where all the code is in one place. Otherwise I'd need to convert each call back to methods' return type, like: CType(CType(number, Decimal).ConvertDistance([from], [to]), Short) or CLng(CDec(number).ConvertDistance([from], [to])) and similar... Redundant casting in this particular case, in my opinion.
Was This Post Helpful? 1
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: Not Using Option Strict

Posted 23 May 2013 - 03:48 PM

lucky3: I don't like uses the plain Double when the value has meaning. It could led to the wrong units being used.
So I like to create a specific type to encode the meaning. Eg Metres, Inches.
As it allows for Compile Time checks.
Spoiler

Was This Post Helpful? 1
  • +
  • -

#8 lucky3  Icon User is offline

  • Friend lucky3 As IHelpable
  • member icon

Reputation: 231
  • View blog
  • Posts: 765
  • Joined: 19-October 11

Re: Not Using Option Strict

Posted 24 May 2013 - 12:04 AM

AdamSpeight2008 I agree with you completely on this particular example. It was used just as an example. It would definitively make more sense to do the same on something like example in intro of that same tutorial, with SinD extension method.
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: Not Using Option Strict

Posted 24 June 2013 - 06:06 PM

Another you may or may not be aware of is that the Options like Option Strict can be code file specific. So you can use Partial and split the code in to multiple files.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1