Programing style

Dar Scott dsc at swcp.com
Fri Nov 17 01:43:37 EST 2006


On Nov 16, 2006, at 5:33 PM, Hershel Fisch wrote:

> by the way what did you by prefix?

I am contrarian in the use of certain letters at the start of names  
to help with readability among team members.  (When a customer has  
style requirements, I follow those, but for my own work, I use other  
ways to help identify variables.)

I tend to write small handlers, about the size of your dollar  
formatting function.  The whole script fits in one view.  I also tend  
to write use a lot of "pure" functions, which by their nature do not  
use globals and script locals.  In those cases those prefixes  
separate the handler local variables and the parameters.  Well, the  
parameters are listed right at the top, so it is easy to tell the  
difference.

Now, some handers do use script locals.  I typically organize my  
scripts into sections and have the script locals for that section  
right at the top and close to the handers that use them.  They are  
documented and are described in section notes.  They are typically  
easy to recognize in handlers even when the declarations have  
scrolled off the screen, since the hander often only gets the data or  
sets the data.  This is probably the weakest place of my argument,  
because a person focusing on a handler might not see the declaration  
at the top of the section or might expect all script local variables  
to be declared at the top of the script.

I very rarely use globals and they are heavily documented.

The syntax identifies properties, so why give them a special prefix?

I use semantic prefixes at times, but those are usually several  
letters or even whole words.  I prefer to make the name work hard for  
readability.  Well, they mean something to me.

Folks who want to make sure their scripts are easily maintained by  
themselves or others do follow the prefix discipline and I understand  
the goals.  I just disagree (and throw candy at advocates at  
conferences).

Dar



More information about the use-livecode mailing list