Vandalf
06-03-2017, 18:59
Consider this code:
Function HALQuote(myname as string) as string
return "I'm sorry, "& myname &", I'm afraid I can't do that."
end function
When "HALQuote(*)" is evaluated, thinBasic has to bear the runtime costs of one function call, checking the argument's type, allocating two strings, and copying the argument's value twice. Compare that to the following:
'#define HALQuote(myname) "I'm sorry, "& myname & ", I'm afraid I can't do that."
When this "HALQuote(*)" appears in source code, thinBasic only needs to allocate one string and copy the argument's value once, without calling a function and without checking types. Although there will be some increased cost in preprocessing time or even runtime, depending on how this concept gets implemented in thinBasic. Also, macros like that must be used carefully, but I think this would be a nice option to have.
Function HALQuote(myname as string) as string
return "I'm sorry, "& myname &", I'm afraid I can't do that."
end function
When "HALQuote(*)" is evaluated, thinBasic has to bear the runtime costs of one function call, checking the argument's type, allocating two strings, and copying the argument's value twice. Compare that to the following:
'#define HALQuote(myname) "I'm sorry, "& myname & ", I'm afraid I can't do that."
When this "HALQuote(*)" appears in source code, thinBasic only needs to allocate one string and copy the argument's value once, without calling a function and without checking types. Although there will be some increased cost in preprocessing time or even runtime, depending on how this concept gets implemented in thinBasic. Also, macros like that must be used carefully, but I think this would be a nice option to have.