Why not an "Option Explicit" for Basic Stamp programming?
Jimbo30
Posts: 129
Seems practical to me and it would make things easier.· It would cut down on errors and trouble-shooting programs, as well.
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