11-16-2022, 04:06 PM
(11-16-2022, 11:44 AM)NasaCow Wrote: Perhaps I have been calling them the wrong thing for a very long time.
What has happened is when I included Ritchie's QB64 Menu Library and tried to switch to OPTION BASE 1, it throws an array out of bounds inside the library when it is ran but it doesn't when the base is set to zero. So my question is with these options or commands (whatever they are called collectively), is there a way to use them only in my main .BAS file and not "bleed over" to the .BI files. Sorry if I was imprecise with my language, a great sin for a programmer
Afraid not, and if you think about it for a moment, you'll see why.
Let's say you write a very simple program:
Code: (Select All)
OPTION BASE 1
REDIM text(0) AS STRING
--stuff
SUB CountLines (file AS STRING, text() AS STRING) 'counts the lines of text in a file and saves them as an array.
OPEN file FOR BINARY AS #1
DO UNTIL EOF(1)
count = count + 1
IF count > UBOUND(text) THEN REDIM _PRESERVE text(count) AS STRING
LINE INPUT #1, text(count)
LOOP
CLOSE 1
END SUB
Simple enough -- you wrote a SUB which counts the lines in an text file and saves them to a string array. Written as is, it works flawlessly.
Now, imagine a few months later, you've assured yourself that this is THE bestest best ever line counting, array storing routine, so you decide to take it out of your program and save it as "CountLines.BM"... You share it with all your friends...
...and suddenly it's not working as advertised!!
It went from a routine inside the main BAS file to simply being one inside a BM file, and now it's not working because that OPTION BASE 1, which you *always* tend to use as default in your programs, doesn't work with the $INCLUDES.
Coding for one's self, a lot of these ideas seem like great ideas. Once one starts coding and releasing that code to the public however, it becomes the wild, wild west out there. Yoiu have to try to imagine not just how people like you would use the commands, but how it'd affect people who's coding style is almost completely foreign to you, and yet they're using the language you've produced.
If "OPTION BASE 1" were included in a *.BI file, how far should that influence reach? Only to that BI file? Only to the file and a similarly named *.BM file? But what if it passes shared variables back to the main program -- would those be BASE 1 or BASE 0? IF the main module has an array called FOO(), and $DYNAMIC is in use, then FOO() is resizable. Now, if there's a REDIM foo() inside an $INCLUDE file, is that foo() resizeable? Is it even the same array, or does it create a new STATIC array now? How's the change to localized Metacommands affected it?
In the wild, wild west of open-source coding, such a command would likely break zillions of old programs. People would start shouting, "AHHH!! MY OLD SHIT DOESN"T WORK ANY MORE!! FIX IT!!!"
v1.5 had a "fix" to recursive functions in it, that changed how they worked for people -- and that STILL gets folks posting about it on a regular basis asking about, "Why my shit no work no more?" That's with just a change to ONE single keyword...
I can't even begin to imagine how many people would faint, explode, and murder someone, if the behavior of all the MetaCommands was suddenly changed on them....