Page 1 of 2

[Implemented] Don't allow undeclared variables

Posted: Tue Oct 28, 2003 12:08 am
by Justin
it can produce hard to find bugs, just make a mistake in a variable name and i'll be assigned a 0 val producing unexpected results without errors

with declaring i just mean initializing, a=0 , a$="" ..

(Implemented as 'EnableExplicit')

Posted: Tue Oct 28, 2003 2:44 pm
by stan
Hi,

I completely agree with you about the bug possibilities, on the other hand it would mean decalring all the variables in my "old" programs, so maybe a slightly better solution : a switch in the compiler options allowing to choose between being obliged to declare or not.

Bests.

Stan.

Posted: Tue Oct 28, 2003 8:14 pm
by Psychophanta
But you are free to declare or not.

For my opinion that should be a serious restriction.

Posted: Tue Oct 28, 2003 9:58 pm
by blueznl
a compiler option would indeed by a serious bug finding helper...

Posted: Wed Oct 29, 2003 1:01 pm
by GedB
Something like VBs Option Explicit would be a great help.

Posted: Wed Oct 29, 2003 2:33 pm
by pthien
Agreed. I've stumbled on this a couple of times already. Simply mistyping a variable name when testing for a condition can take several minutes to spot. Perhaps a warning rather than stopping compilation?

Thanks,
Phil

Posted: Fri Oct 31, 2003 1:26 pm
by Jan Vooijs
@all, we agree but how about FRED, he has to oke this and built it in!!

Please FRED build this "option explicit" into Pure this is needed!!

Just simple an option into the sources or an extra parameter option!
I prefer the first IN the sources!!

Jan

Posted: Fri Oct 31, 2003 1:56 pm
by freedimension
In the Meanwhile, for Global Variables you could just use a Structure. Structures are checked against wrong members.

Code: Select all

Structure global
  myVar1
  ...
EndStructure

global.global

global\mayVar1 ;this will not work

Posted: Fri Oct 31, 2003 10:20 pm
by Jan Vooijs
@freedimension, thanks for the tip but that complicates the matter to a large extend!! That is NOT workable for me, any one??

Jan

Posted: Mon Nov 03, 2003 4:39 pm
by Shopro
I agree to adding an option to force the declaration of variables.

Posted: Mon Nov 03, 2003 10:07 pm
by tinman
Someone once wrote a "source code checker" for this situation for the original Blitz Basic II on the Amiga. The source is available should anyone want to port it to PB (should be similar enough to not be a massive job - probably not a small one though :) and use it as a stop-gap until this gets put into PB.

Blitz-2000 site - although there seems to be problems with the server currently.

Posted: Mon Nov 03, 2003 10:08 pm
by Blade
Agree.
50% of possible common bugs will never appear again!

Posted: Tue Nov 04, 2003 10:20 am
by einander
Simply asking "New Var : XXX?"
each time that a new variable is introduced would be a great help.

Posted: Fri May 14, 2004 7:09 pm
by gomio
You can try this:

(begin of program)
structure DefaultType: endstructure
deftype.DefaultType
(...)
foo = 0 ; <--- error
bar = ":-)" ; <--- error, etc.

Re: Don't allow undeclared variables

Posted: Fri May 14, 2004 7:15 pm
by NoahPhense
I like the 'Option Explicit' idea myself..

- np