05-18-2024, 12:14 PM
(05-18-2024, 11:57 AM)dbox Wrote: This looks like a good addition and I can certainly see where it removes the need for pre-processor variable checks that can be used to prevent multiple $Include’s of the same file. Out of curiosity, why was this added as a new keyword rather than an improvement to $Include? Is there a use case where the old behavior would be preferred where this might break backwards compatibility?
Let's write a couple of simple programs, and you'll see the issue instantly, I think.
First, let's write COUNT.BAS:
Code: (Select All)
Count = Count + 1
Now, let's write another that is just as complicated. Let's call this RESULTS.BAS:
Code: (Select All)
'$INCLUDE:'COUNT.BAS'
'$INCLUDE:'COUNT.BAS
'$INCLUDE:'COUNT.BAS
'$INCLUDE:'COUNT.BAS
PRINT Count
Save the first.
Run the second.
See the result is now printed on your screen as: "4".
Sometimes, for whatever odd reason, folks might want to include the same file in multiple places, or multiple times. (I think I'd rather just make a SUB or FUNCTION and then call it multiple times, but in the end, I only write *MY* code and others have to decide what suits their styles the best.)
From the above, I think you can see why we wouldn't want to change $INCLUDE so it only loaded a file once. Who knows how many people's old code might break with such a change?
I suppose we could've added it as a new optional paramter with $INCLUDE, but I honestly don't think that'd be any simpler or better.
$INCLUDE:'foo.bas' _ONLYONCE
^The problem I see with the above is that the file is now restriced by that $INCLUDE, which may not be the first in some list of load order. Think of the following:
Code: (Select All)
$INCLUDE:'foo.bas'
'stuff
$INCLUDE:'foo.bas' _ONLYONCE
I think that type of behavior would get hard to track, debug, and deal with fairly fast.
Much better to set the line in the file you DON'T want included multiple times, and then have that forevermore flagged as a "single load" only file, I think.