Some simple macros to help make code more readable
Posted: Thu Aug 23, 2012 2:55 am
Even though the PB macro support is quite primitive, we've made use of it to help implement a simplified OOP (SOOP). However, we also use macros for more mundane things.
Here are a few simple macros to make code a little more readable. These are some of the 100 or so macros that we use in our shop to simplify the coding process and make the code less opaque.
In this first example we change the Select block so that it has a similar look to the If block:
Although While/Wend is a looping contruct related to Repeat and For, the use of the word Wend makes it look more like a non-looping block, like If/EndIf. So we change things a little to make the looping more obvious:
Lastly, here are some examples related to the Break statement. In complex code, the Break Level doesn't make it obvious which loops are involved. Our macros make this clearer by including the loop types in the macro name. Here are a few examples:
Here are a few simple macros to make code a little more readable. These are some of the 100 or so macros that we use in our shop to simplify the coding process and make the code less opaque.
In this first example we change the Select block so that it has a similar look to the If block:
Code: Select all
Macro CaseElse
Default
EndMacro
Select ......
Case .....
Case .....
CaseElse
EndSelect
Although While/Wend is a looping contruct related to Repeat and For, the use of the word Wend makes it look more like a non-looping block, like If/EndIf. So we change things a little to make the looping more obvious:
Code: Select all
Macro Loop
Wend
EndMacro
While .....
Loop
Lastly, here are some examples related to the Break statement. In complex code, the Break Level doesn't make it obvious which loops are involved. Our macros make this clearer by including the loop types in the macro name. Here are a few examples:
Code: Select all
Macro ExitFor
Break
EndMacro
Macro ExitRepeat
Break
EndMacro
Macro ExitWhile
Break
EndMacro
Macro ExitForFor ; this breaks from 2 nested For loops
Break 2
EndMacro
Macro ExitForWhile ; this breaks from a For loop and its outer While loop
Break 2
EndMacro
Repeat
ExitRepeat
Until .....
While .....
ExitWhile
For .....
ExitForWhile
For .....
ExitFor
ExitForFor
Next
Next
Loop