I know a few do, but this is something that came to mind recently after observing a number snippets. I have always used constants as variables that do not change; but they are more than that in DBPRO.
Constants tell the compiler to replace a constant name with literal code; the code can be a calculation, a series of function calls, text, data or a series of keywords.
Does anybody use it to insert an entire line of code without having to retype it? I have not.
This is not me trying to encourage laziness; I am just curious if anybody is doing it, because it appears to make sense, why not tell the computer how to do something instead of just telling it what to do. Something like
Type PlayerType
Obj
Endtype
Dim P(10) as PlayerType
Global Player as PlayerType
#constant FOR_EACH_PLAYER For IndexOfPlayer = 0 to Array Count( P() ) : Player = P(IndexOfPlayer )
#constant UPDATE_PLAYER P(IndexOfPlayer) = Player
#constant NEXT_PLAYER Next IndexOfPlayer
FOR_EACH_PLAYER
Player.Obj = Rnd(100)
UPDATE_PLAYER
Print P(IndexOfPlayer).Obj
NEXT_PLAYER
So you end up with something like this when you simply need to query a list of something common like a player:
FOR_EACH_PLAYER
Move Object Player.Obj
NEXT_PLAYER
This is a more tidier way to read something like this:
For IndexOfPlayer = 0 to Array Count( P() ) : Player = P(IndexOfPlayer )
Move Object Player.Obj
Next IndexOfPlayer
Both snippets do the same thing. It seems like a cool way to insert your own snippets, but needs discipline to make sure the snippets are clean and correct; it is almost like creating keywords; something regular functions could not achieve with local variables (Although my example is working with globals)
Another example is used in Diggseys TopGUI, where GEN_ID is an easier term to write than INDEX_ID(0). Another example is GAME_TIME$ rather than GameTime$( CurrentDay, CurrentHour, CurrentMinute).
Updating the constant is always easier than updating literals; and the advantage over functions is that you can engineer your own branch statements using a series of regular branch statements that work with the UDT, memblock, bank, net packet or what ever it is the block of code is for. You can update such things in one place and not have to repeat yourself as much.
Perhaps someone who has practiced this over a long time is aware of any disadvantages...