[Implemented] Don't allow undeclared variables

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

[Implemented] Don't allow undeclared variables

Post 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')
stan
User
User
Posts: 29
Joined: Tue Jun 10, 2003 2:46 pm

Post 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.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

But you are free to declare or not.

For my opinion that should be a serious restriction.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

a compiler option would indeed by a serious bug finding helper...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
GedB
Addict
Addict
Posts: 1313
Joined: Fri May 16, 2003 3:47 pm
Location: England
Contact:

Post by GedB »

Something like VBs Option Explicit would be a great help.
pthien
Enthusiast
Enthusiast
Posts: 150
Joined: Sun Jun 29, 2003 9:39 pm

Post 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
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post 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
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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
Jan Vooijs
Enthusiast
Enthusiast
Posts: 196
Joined: Tue Sep 30, 2003 4:32 pm
Location: The Netherlands

Post 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
Life goes to Fast, Enjoy!!

PB 4 is to good to be true, wake up man it is NOT a dream THIS is a reality!!!

AMD Athlon on 1.75G, 1Gb ram, 160Gb HD, NVidia FX5200, NEC ND-3500AG DVD+RW and CD+RW, in a Qbic EO3702A and Win XP Pro SP2 (registered)
Shopro
Enthusiast
Enthusiast
Posts: 148
Joined: Tue May 13, 2003 8:05 am

Post by Shopro »

I agree to adding an option to force the declaration of variables.
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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.
Last edited by tinman on Mon Nov 03, 2003 10:10 pm, edited 2 times in total.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Blade
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Aug 06, 2003 2:49 pm
Location: Venice - Italy, Japan when possible.
Contact:

Post by Blade »

Agree.
50% of possible common bugs will never appear again!
User avatar
einander
Enthusiast
Enthusiast
Posts: 744
Joined: Thu Jun 26, 2003 2:09 am
Location: Spain (Galicia)

Post by einander »

Simply asking "New Var : XXX?"
each time that a new variable is introduced would be a great help.
gomio
New User
New User
Posts: 1
Joined: Sat May 17, 2003 6:10 pm
Location: Granada, España

Post by gomio »

You can try this:

(begin of program)
structure DefaultType: endstructure
deftype.DefaultType
(...)
foo = 0 ; <--- error
bar = ":-)" ; <--- error, etc.
User avatar
NoahPhense
Addict
Addict
Posts: 1999
Joined: Thu Oct 16, 2003 8:30 pm
Location: North Florida

Re: Don't allow undeclared variables

Post by NoahPhense »

I like the 'Option Explicit' idea myself..

- np
Post Reply