Page 1 of 1
variable naming conventions
Posted: Thu Apr 29, 2010 4:30 pm
by ninetrees
In trying to understand some of the code samples, I find some naming conventions used that I don't understand, hence they're not helping me understand the code: what is implied by the prefix "t" and "p" for variables. (g or g_ I understand to indicate a global var) such as
Code: Select all
# Filters the strings "." and ".." from a list
function filterDots pList
local tList
put pList into tList
filter tList without "."
filter tList without ".."
return tList
end filterDots
Also, for boolean values, I append "Flag" usually. Other suggestions?
Re: variable naming conventions
Posted: Thu Apr 29, 2010 4:57 pm
by bn
Hello ninetree,
p stands for parameter and t stands for temp (i guess) it is used to prepend a varible name inside a handler that stays strictly in this handler.
I use s to indicate script local variables, those are variables that are accessible to all handlers in one script. Some people use u to indicate a custom property.
look at this article by Richard Gaskin
http://www.fourthworld.com/embassy/arti ... style.html
naming conventions explains the idea behind this.
It took me a while to pick up this habit but it really helps to instantly see the scope of the variable.
regards
Bernd
Re: variable naming conventions
Posted: Thu Apr 29, 2010 5:35 pm
by mwieder
I also follow the guidelines laid out in Richard's article. It wasn't hard to get used to the idea, and it does make reading and following the code much easier.
I think it doesn't really matter whether or not you follow all the guidelines there as long as you stick with *some* consistent format. Whatever works for you. But one of the reasons I do follow Richard's guidelines is that is makes the code consistent across multiple programmers - someone else will have an easier time reading my code if it already matches the guidelines they're using; and I'll have an easier time reading someone else's code if they're using coding guidelines that I'm already used to.
I also prepend "lbl" to label field names, "btn", "chk", "rdo" to button names, etc. Not necessary, but it's a holdover from other programming environments and it makes it easier for me to tell at a glance whether my code is acting on a radio button or a checkbox.
Re: variable naming conventions
Posted: Fri Apr 30, 2010 5:01 am
by ninetrees
Thanks. Just what I was looking for. I try to be careful with my conventions, but the guide suggests some things I'd not thought about before.
Re: variable naming conventions
Posted: Fri Apr 30, 2010 7:06 am
by FourthWorld
mwieder wrote:I also prepend "lbl" to label field names, "btn", "chk", "rdo" to button names, etc. Not necessary, but it's a holdover from other programming environments and it makes it easier for me to tell at a glance whether my code is acting on a radio button or a checkbox.
Like a lot of the stuff in the Scripting Style Guide, that's another example of GMTA.

I started using "lbl" prefixes for non-editable fields a while back, and I find it makes them so much easier to distinguish in scripts and in a control browser.
It's funny how so many scripters stumble into the same habits independently. One of the things that compelled me to write the Guide was noticing how frequently those conventions were being used by so many so many different scripters who'd never traded code before.