variable naming conventions

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
ninetrees
Posts: 7
Joined: Thu Apr 22, 2010 6:54 am

variable naming conventions

Post by ninetrees » Thu Apr 29, 2010 4:30 pm

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?

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: variable naming conventions

Post by bn » Thu Apr 29, 2010 4:57 pm

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

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: variable naming conventions

Post by mwieder » Thu Apr 29, 2010 5:35 pm

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.

ninetrees
Posts: 7
Joined: Thu Apr 22, 2010 6:54 am

Re: variable naming conventions

Post by ninetrees » Fri Apr 30, 2010 5:01 am

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9842
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: variable naming conventions

Post by FourthWorld » Fri Apr 30, 2010 7:06 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”