Constant command

Mark Wieder mwieder at ahsoftware.net
Sat Oct 16 00:18:00 CDT 2010


Robert-

Thursday, October 14, 2010, 3:54:33 PM, you wrote:

> As others said, this is a matter of programming style. What I often
> use script-wide constants for is for names of objects user interacts
> with. For example, on a card level, I may have several handlers that
> refer to a button or a field (for example, resizestack, scripts that
> handle GUI). Using constant is just convenient. Using script locals 

I also use constants to eliminate having magic numbers sprinkled
throughout my scripts. I place them at the top of the script to make
them manageable. Then when I want to change all the indentations in
half a dozen fields, I just have one place to change it. Or I might
define a list of constant values for the rawKeyDown values of the
arrow keys so I can see them all in one place, use the constant names
instead of the values so I don't accidentally key in the wrong one,
and make my code more readable, i.e.,

switch pKeyCode
  case kBackSpaceKey
  case kDeleteKey
    pass rawKeyUp
    break
end switch

is much more readable than

switch pKeyCode
  case 65288 -- the backspace key
  case 65535 -- the Delete key
    pass rawKeyUp
    break
end switch

-- 
-Mark Wieder
 mwieder at ahsoftware.net




More information about the use-livecode mailing list