"option explicit" is a QBasic, VB6 & VB.NET option that requires all variables to be explicitly defined. Without it variables are implicitly defined when you refer to them.
For example if you have a variable called "whatever" and you accidently type "whatevrr" later in your program. It may take a while to track down the missed spelled variable. "option explicit" would cause a compile error so you immediately know of the bad variable.
Except for a limited set of pre-defined variables, all variables in Parallax Basic must be explicitly defined. The same is true for Spin, so you don't need "option explicit".
I knew SPIN was explicit. As that's my language of choice on the Propeller currently.
Now I'm curious on what Jimbo30 meant, as "option explicit" has a very specific meaning to me; and I use it to prevent the the problems that Jimbo30 is alluding to.
PBasic Editor, do that when you Syntax Check the program code. Syntax Chek shows all misspelled variables and/or other misspelled commands and wrong charcters, it happens also when you try to look at the Memory Map or if you push Run (download) a code with misspelled variable to BS2 without a Syntax Chek.
What I was trying to get at was when using "option explicit" in VB any misspelled or case sensitive variables are corrected automatically. But I guess electrosys answered my question with PBASIC and the Syntax Check. Though with VB all you have to do is include "option explicit" at the beginning of your programming. So why couldn't PBASIC have some type of command a user would type at the beginning for automatic corrections?
Oh, you mean some "auto-complete" or "auto-check" option? I don't know -- when you've got a device with only 2Kbytes of eeprom, raising expectations like that might be counter-productive.
Jimbo30 said...
What I was trying to get at was when using "option explicit" in VB any misspelled or case sensitive variables are corrected automatically. But I guess electrosys answered my question with PBASIC and the Syntax Check. Though with VB all you have to do is include "option explicit" at the beginning of your programming. So why couldn't PBASIC have some type of command a user would type at the beginning for automatic corrections?
What you describe here is less "option explicit" behavior, and more "intellisense" behavior.
The editor maintains "knowledge" keywords and defined variables, and does some automatic checking and "suggested entry" as you type.
In VB, without Option Explicit turned on, the editor does not know if you're trying to define a new variable or not.
These features are not really part of the language, but part of the editor/IDE environment.
In the "for what it's worth" category, the lack of requiring variables to be declared is one of the significant reasons that VB is not considered a "real" language by many. There are other weaknesses that also contribute. On the flip side, some of these weaknesses are what make it so easy to get "something" up and running.
Automatic corrections are potentially dangerous. There are languages where variables are automatically declared by default. Too often, they're misspellings of existing variables and you end up with two separate variables with slightly different names. Once you have the compiler guess whether the new spelling is close enough to an existing variable to ask you what you meant to do, that's not much different from having the compiler flag undefined variables or labels as errors. Particularly with PBasic where programs are small, having the compiler flag undefined variables or labels as errors is not a problem.
Generally speaking, it's better to require declarations and declarations that give as much information as possible about how a variable is used so the compiler can check that and help you find actual errors. I have a lot of experience with Pascal and other strongly typed languages as well as with weakly typed languages. C, for example, can be used either way. A good compiler for a strongly typed language can really save you a lot of difficult debugging time by pointing out where you've probably made a mistake or at least should carefully consider what you've written and perhaps change it to reflect better what you've intended.
as the worst speller in the world, I absolutly love intellisence. I program primaraly in VB 6 and it saves me time. But I spend way more time get and put than ever declarin var's so I don't realy see a need for it in pbasic. The thing I love about intellisence primaraly is the ability to select methods, events and variables from a class or moduel. saves alot of lookups for me and I never miss spell them.
While VB has its faults it also has its strengths. primaraly I use VB due to VBS in office and autocad. My familiarity and its ease of use make it super productive for me. I spent a week writing an app at work to automaticaly update our title blocks on our drawings. My boss was ticked that friday when he found I had done only 100 drawing updates compared to the 600 my partner did, then come monday I turned in my 4000 drawing updates in the first hr and started on the next batch from a difrent company. Getting the format right from plant to plant was a bit tricky but patterns emerge and it all works out in the end lol. Needless to say I never did a batch of drawing rev's again, they moved me into the development eng lab 2 weeks later. Thank you VB.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A woman is the only thing I am afraid of that I know will not hurt me. - Abraham Lincoln
In college I had some run-ins with a language called PL/C. It was a PL/I derivative designed for teaching programming. One of its touted "benefits" was that it could correct minor program errors so the program could run in spite of them. Only thing was, it almost always made things worse instead of better by inferring the wrong corrections.
The Perl language has a pragma called strict which, when specified, requires explicit declarations for all variables and subroutines. Perl programmers are constantly exhorted to use strict because doing so can flag a host of woes. Most Perl compilers will also warn you if a symbol is referenced only once. Such an event is almost always either an error or some crufty detritus left in the program from an earlier version or a debugging attempt.
The main point I'm trying to make is that humans are smarter than compilers when it comes to fixing things; but, given half a chance, a properly conceived compiler is more thorough than a human when it comes to finding and flagging what needs fixing.
I don't think I have ever seen an IDE that auto corrects. Intellisence just shows a list of options below what you are typeing and thier selectable. Option explicit flags vars that havent been declared on run.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A woman is the only thing I am afraid of that I know will not hurt me. - Abraham Lincoln
Comments
For example if you have a variable called "whatever" and you accidently type "whatevrr" later in your program. It may take a while to track down the missed spelled variable. "option explicit" would cause a compile error so you immediately know of the bad variable.
Jay
I knew SPIN was explicit. As that's my language of choice on the Propeller currently.
Now I'm curious on what Jimbo30 meant, as "option explicit" has a very specific meaning to me; and I use it to prevent the the problems that Jimbo30 is alluding to.
Jay
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
What you describe here is less "option explicit" behavior, and more "intellisense" behavior.
The editor maintains "knowledge" keywords and defined variables, and does some automatic checking and "suggested entry" as you type.
In VB, without Option Explicit turned on, the editor does not know if you're trying to define a new variable or not.
These features are not really part of the language, but part of the editor/IDE environment.
In the "for what it's worth" category, the lack of requiring variables to be declared is one of the significant reasons that VB is not considered a "real" language by many. There are other weaknesses that also contribute. On the flip side, some of these weaknesses are what make it so easy to get "something" up and running.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John R.
Click here to see my Nomad Build Log
Generally speaking, it's better to require declarations and declarations that give as much information as possible about how a variable is used so the compiler can check that and help you find actual errors. I have a lot of experience with Pascal and other strongly typed languages as well as with weakly typed languages. C, for example, can be used either way. A good compiler for a strongly typed language can really save you a lot of difficult debugging time by pointing out where you've probably made a mistake or at least should carefully consider what you've written and perhaps change it to reflect better what you've intended.
While VB has its faults it also has its strengths. primaraly I use VB due to VBS in office and autocad. My familiarity and its ease of use make it super productive for me. I spent a week writing an app at work to automaticaly update our title blocks on our drawings. My boss was ticked that friday when he found I had done only 100 drawing updates compared to the 600 my partner did, then come monday I turned in my 4000 drawing updates in the first hr and started on the next batch from a difrent company. Getting the format right from plant to plant was a bit tricky but patterns emerge and it all works out in the end lol. Needless to say I never did a batch of drawing rev's again, they moved me into the development eng lab 2 weeks later. Thank you VB.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A woman is the only thing I am afraid of that I know will not hurt me. - Abraham Lincoln
In college I had some run-ins with a language called PL/C. It was a PL/I derivative designed for teaching programming. One of its touted "benefits" was that it could correct minor program errors so the program could run in spite of them. Only thing was, it almost always made things worse instead of better by inferring the wrong corrections.
The Perl language has a pragma called strict which, when specified, requires explicit declarations for all variables and subroutines. Perl programmers are constantly exhorted to use strict because doing so can flag a host of woes. Most Perl compilers will also warn you if a symbol is referenced only once. Such an event is almost always either an error or some crufty detritus left in the program from an earlier version or a debugging attempt.
The main point I'm trying to make is that humans are smarter than compilers when it comes to fixing things; but, given half a chance, a properly conceived compiler is more thorough than a human when it comes to finding and flagging what needs fixing.
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
A woman is the only thing I am afraid of that I know will not hurt me. - Abraham Lincoln