Author Topic: New command: OPTION _EXPLICITARRAY  (Read 3303 times)

0 Members and 1 Guest are viewing this topic.

Offline luke

  • Administrator
  • Seasoned Forum Regular
  • Posts: 324
    • View Profile
New command: OPTION _EXPLICITARRAY
« 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:
Code: [Select]
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.

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: New command: OPTION _EXPLICITARRAY
« Reply #1 on: July 15, 2020, 10:27:04 am »
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.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: New command: OPTION _EXPLICITARRAY
« Reply #2 on: July 15, 2020, 10:31:55 am »
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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline loudar

  • Newbie
  • Posts: 73
  • improve it bit by bit.
    • View Profile
Re: New command: OPTION _EXPLICITARRAY
« Reply #3 on: July 15, 2020, 10:52:39 am »
I would be very much excited for this! Definitely in favor of the OPTION EXPLICIT to take options.
Check out what I do besides coding: http://loudar.myportfolio.com/

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: New command: OPTION _EXPLICITARRAY
« Reply #4 on: July 15, 2020, 01:20:08 pm »
The easiest way to complete a job is to NOT tell anyone about it, until it's completed! :D

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/