TI-994A wrote:Hello BorisTheOld. Personally, I believe that macros are more for reducing repetitive tasks than for increasing readability. A laconic listing is just a bonus, but debugging such code can be very tiresome.
But, only if you plan to write code that has bugs in it. A toolbox full of macros, modules, and classes, essentially eliminates coding errors.
TI-994A wrote:In another thread
(link), you mentioned using some in-house tool for expanding macros. Seems that you too have a need for such a utility, and perhaps you'd be kind enough to share that with us?

There are macros, and then there are macros. We use different types for different purposes.
The text substitution macros, mentioned in the link, are used when writing templates for the code generators in our Data Dictionary software. We use a separate class of macros when writing actual PB code. These macros add clarity to the code and provide standard BASIC features that are missing from PB. In particular, supporting OOP without getting bogged down in PB syntax.
The following trivial statements in a Data Dictionary script:
Code: Select all
{for} iFromPtr {from} 1 {to} 19
{if} {getmid}sRegistrationNumber, iFromPtr, 1{/getmid} <> {c}CHAR_MINUS {then}
{incr}iToPtr{/incr}
{setmid}sWork, iToPtr, 1{setto}{getmid}sRegistrationNumber, iFromPtr, 1{/getmid}{/setmid}
{/if}
{/for}
will produce the following source code for PowerBasic:
Code: Select all
For iFromPtr = 1 To 19
If Mid$(sRegistrationNumber, iFromPtr, 1) <> $cCHAR_MINUS Then
Incr iToPtr
Mid$(sWork, iToPtr, 1) = Mid$(sRegistrationNumber, iFromPtr, 1)
End If
Next
but will produce the following source code for PureBasic, which is readable:
Code: Select all
For iFromPtr = 1 To 19
If MidGet(sRegistrationNumber, iFromPtr, 1) <> #cCHAR_MINUS Then
Increment(iToPtr)
MidSet(sWork, iToPtr, 1, MidGet(sRegistrationNumber, iFromPtr, 1))
EndIf
Next
which, with the application of our PB macros, reduces to the following PB code, which is not so readable:
Code: Select all
For iFromPtr = 1 To 19
If Mid(sRegistrationNumber, iFromPtr, 1) <> #cCHAR_MINUS
iToPtr = iToPtr + 1
gloApp\subMidSet (@sWork, Len(sWork), iToPtr, 1, Mid(sRegistrationNumber, iFromPtr, 1), 1)
EndIf
Next