Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extended KotD #7: $INCLUDEONCE
#4
(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.  Wink

First, let's write COUNT.BAS:
Code: (Select All)
Count = Count + 1
Phew!!  That's one complicated program!

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
Now, obviously, this isn't any sort of complex code that's going to end up bringing a stop to world hunger or anything.  All this is, is a quick illustration of WHY $INCLUDE itself wasn't changed.  Wink

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
Now, does that _ONLYONCE only apply from the point where it first appears onwards?  Does that mean the first $Include is valid, so it's not *really* an _OnlyOnce type deal???

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.  Wink
Reply


Messages In This Thread
Extended KotD #7: $INCLUDEONCE - by SMcNeill - 05-15-2024, 07:17 AM
RE: Extended KotD #7: $INCLUDEONCE - by grymmjack - 05-16-2024, 09:52 PM
RE: Extended KotD #7: $INCLUDEONCE - by dbox - 05-18-2024, 11:57 AM
RE: Extended KotD #7: $INCLUDEONCE - by SMcNeill - 05-18-2024, 12:14 PM
RE: Extended KotD #7: $INCLUDEONCE - by dbox - 05-18-2024, 03:32 PM
RE: Extended KotD #7: $INCLUDEONCE - by RhoSigma - 05-18-2024, 05:39 PM
RE: Extended KotD #7: $INCLUDEONCE - by bobalooie - 05-22-2024, 11:38 PM



Users browsing this thread: 2 Guest(s)