Option Explicit

  • Thread starter Thread starter Doug Hill
  • Start date Start date
D

Doug Hill

Please, Microsoft, update Option Explicit

Option Strict barks at late binding. We love late
binding. So Option Strict flags too many things.

Option Explicit is misleading.
It allows
Dim LastName

rather than forcing
Dim LastName as string

Option Explicit should force the data type.
Option Explicit should also force functions to be
delared with a return data type.

The reason I'm harping is I just reviewed a Jr programmers
code and the code was full of Dim variables without data
types.
 
I agree that Option Explicit should enforce a data type.

While late binding is convenient it is extremely inefficient, so while
Option Strict = On (by the way, notice that MS defaults this to Off) is more
of a pain, you wind up with less opportunity for type mismatches and better
performance.

IMHO :)
 
Doug,
It seems your request is at odds with itself! :-)

Option Explicit On requires you to define the variable:
Dim LastName

Option Strict Off is allowing (defaults) that variable or function to be an
Object, as you are allowed to use late binding on it.
Dim LastName As Object

Personally the behavior makes sense.

Are you asking you want the compiler to force you to include the 'As Object'
so you can do the late binding?

You could use the MS Wish site to submit your suggestion to MS.

http://register.microsoft.com/mswish/suggestion.asp?&SD=GN&LN=EN-US&gssnb=1

Generally I avoid Late Binding as it is far too easy to introduce far too
many runtime bugs. When I do need to use Late Binding I isolate it in one or
two modules in a far corner of my application.

However having the option is nice!

Have you looked at getting a Code Critic or Code Analyzer that your Jr
Programmers can run on the code to identify variables that are implicitly
defined as Object?

http://www.fmsinc.com/dotnet/analyzer/

Note I have not actually used the above, I just see value of Code Critics.
For just what you are asking.

Hope this helps
Jay
 
Thank you Jay and Scott
-----Original Message-----
Doug,
It seems your request is at odds with itself! :-)

Option Explicit On requires you to define the variable:

Option Strict Off is allowing (defaults) that variable or function to be an
Object, as you are allowed to use late binding on it.


Personally the behavior makes sense.

Are you asking you want the compiler to force you to include the 'As Object'
so you can do the late binding?

You could use the MS Wish site to submit your suggestion to MS.

http://register.microsoft.com/mswish/suggestion.asp? &SD=GN&LN=EN-US&gssnb=1

Generally I avoid Late Binding as it is far too easy to introduce far too
many runtime bugs. When I do need to use Late Binding I isolate it in one or
two modules in a far corner of my application.

However having the option is nice!

Have you looked at getting a Code Critic or Code Analyzer that your Jr
Programmers can run on the code to identify variables that are implicitly
defined as Object?

http://www.fmsinc.com/dotnet/analyzer/

Note I have not actually used the above, I just see value of Code Critics.
For just what you are asking.

Hope this helps
Jay




.
 
Option Explicit should force the data type.
Option Explicit should also force functions to be
delared with a return data type.

The reason I'm harping is I just reviewed a Jr programmers
code and the code was full of Dim variables without data
types.

While I agreee that this would be useful, In the meantime, your Jr
programmers should follow best coding practices. They need to be educated.
Perhaps you could create a "coding standards" document and require them to
follow it.

Just a thought,

Chris
 
* "Doug Hill said:
Please, Microsoft, update Option Explicit

Option Strict barks at late binding. We love late
binding. So Option Strict flags too many things.

Option Explicit is misleading.
It allows
Dim LastName

rather than forcing
Dim LastName as string

Option Explicit should force the data type.
Option Explicit should also force functions to be
delared with a return data type.

The reason I'm harping is I just reviewed a Jr programmers
code and the code was full of Dim variables without data
types.

I would like 'Option Strict Off' blocks:

\\\
..
..
..
Option Strict Off
 
Hi Herfried,

We'll get them, sort of, in the next release - Partial Types. (But a bit
silly if your O.S.Off block is only a few lines long).

Regards,
Fergus
 
Doug Hill said:
The reason I'm harping is I just reviewed a Jr programmers
code and the code was full of Dim variables without data
types.


I guess i would consider myself a "junior programmer", however, I would not be allowed to get away
with this. This is something that is BASIC programming practice. This sounds more like an
employee management issue than an option explicit not functioning correctly issue.
 
* "Fergus Cooney said:
We'll get them, sort of, in the next release - Partial Types. (But a bit

AFAIk partial types will only be available in C#.
silly if your O.S.Off block is only a few lines long).

I think that's the big advantage of these blocks.

;-)
 
Rick and Chris,
You are absolutely right. I couldn't believe a programmer
would not type variables, and I couldn't believe the tool
let them.
In talking with my bosses I mentioned that I have probably
50 rules that I always follow. Now they want me to
document them. ;-)
Thanks
 
In talking with my bosses I mentioned that I have probably
50 rules that I always follow. Now they want me to
document them. ;-)

Can you send them to us too? ;)
 
Back
Top