QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: luke on July 15, 2020, 07:35:07 am
-
We're all (hopefully) familiar with OPTION _EXPLICIT, which demands all variables be DIMmed before use. We now also have OPTION _EXPLICITARRAY, which is similar but only applies to arrays. This means you need to DIM your arrays, but not your regular variables. Example:
OPTION _EXPLICITARRAY
x = 1 'This is fine, it's not an array so not affected
y(2) = 3 'This now generates an error
DIM z(5)
z(2) = 3 'All good again, we've explicitly DIMmed our array
Available in the development builds.
-
Some of us might take the view: "Well here's a command we don't need"!
An array is something which has Dimensions and jolly well needs to be DIMmed beforehand. I know that there is some default array size, but it must be good practice to DIM any new array.
-
Why not set option explict to take a few optioms?
Variables, shared, arrays...
Personally, I find it unsuitable in my code, just for the error it generates with SHARED in subs. The point of using SHARED in a SUB/FUNCTION (for me, at least), is so that an $INCLUDE library doesn’t need a *.BI file to declare internal variables that are only passed and used in the library routines, and as it currently exists, OPTION EXPLICIT prevents that.
If there’s going to be a toggle for arrays only, why not just make it a binary switch?
variables = 1
shared = 2
arrays = 4
OPTION EXPLICIT: VARIABLES, SHARED would check everything but arrays.
OPTION EXPLICIT: ARRAYS would only check arrays
OPTION EXPLICIT: VARIABLES, ARRAYS checks all but the SHARED
Expanded customization of the command, to suit the users exact desires.
-
I would be very much excited for this! Definitely in favor of the OPTION EXPLICIT to take options.
-
The easiest way to complete a job is to NOT tell anyone about it, until it's completed! :D
Pete