Discussion:
Object Naming Conventions
Pete
2011-10-06 19:23:11 UTC
Permalink
I vaguely remember a thread on this topic a while back. I'm interested in
what naming conventions people have for stacks/cards/controls, if any.

This is in connection with a project I'm working on to automate laying out
controls on a card. I'm currently using a naming convention of my own but
I'd like to provide a way for other conventions to be used, in particular
the use of prefix or suffix characters in names of different types of
objects.

Any input is most welcome.

Pete
Molly's Revenge <http://www.mollysrevenge.com>
Phil Davis
2011-10-06 19:28:38 UTC
Permalink
Here is an excellent starting point:
http://fourthworld.com/embassy/articles/scriptstyle.html

Go to the "Naming Conventions" part.

Phil
Post by Pete
I vaguely remember a thread on this topic a while back. I'm interested in
what naming conventions people have for stacks/cards/controls, if any.
This is in connection with a project I'm working on to automate laying out
controls on a card. I'm currently using a naming convention of my own but
I'd like to provide a way for other conventions to be used, in particular
the use of prefix or suffix characters in names of different types of
objects.
Any input is most welcome.
Pete
Molly's Revenge<http://www.mollysrevenge.com>
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
--
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net
Mark Wieder
2011-10-07 01:03:39 UTC
Permalink
Phil-
Post by Phil Davis
http://fourthworld.com/embassy/articles/scriptstyle.html
Go to the "Naming Conventions" part.
In addition to what's in Richard's writeup I tend to use the following
conventions. Mostly just a carryover from other development
environments since they don't really do much, but they tend to trigger
the same neuron activity so it makes it easier for me to conceptualize
what I'm doing:

control prefix example
---------------------------
buttons : "btn" : "btnSave"
radio buttons : "rdo" : "rdoOption1"
checkboxes : "chk" : "chkShowLineNumbers"
tab buttons : "mnu" : "mnuMainTabForm"
fields : "fld" : "fldHandlers"
labels : "lbl" : "lblSourceCode"
groups : "grp" : "grpGraphicControls"

The only other rule of thumb I have is to keep object names one word
rather than having spaces in the middle. And of course, that rule,
like any other rule, was made to be broken when needed.
--
-Mark Wieder
***@ahsoftware.net
Pete
2011-10-07 01:36:05 UTC
Permalink
Thanks Mark, that's what I was looking for.
Pete
Molly's Revenge <http://www.mollysrevenge.com>
Post by Mark Wieder
Phil-
Post by Phil Davis
http://fourthworld.com/embassy/articles/scriptstyle.html
Go to the "Naming Conventions" part.
In addition to what's in Richard's writeup I tend to use the following
conventions. Mostly just a carryover from other development
environments since they don't really do much, but they tend to trigger
the same neuron activity so it makes it easier for me to conceptualize
control prefix example
---------------------------
buttons : "btn" : "btnSave"
radio buttons : "rdo" : "rdoOption1"
checkboxes : "chk" : "chkShowLineNumbers"
tab buttons : "mnu" : "mnuMainTabForm"
fields : "fld" : "fldHandlers"
labels : "lbl" : "lblSourceCode"
groups : "grp" : "grpGraphicControls"
The only other rule of thumb I have is to keep object names one word
rather than having spaces in the middle. And of course, that rule,
like any other rule, was made to be broken when needed.
--
-Mark Wieder
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Richard Gaskin
2011-10-07 14:41:27 UTC
Permalink
Post by Pete
Thanks Mark, that's what I was looking for.
Pete
Post by Mark Wieder
Phil-
Post by Phil Davis
http://fourthworld.com/embassy/articles/scriptstyle.html
Go to the "Naming Conventions" part.
In addition to what's in Richard's writeup I tend to use the following
conventions...
Good stuff, Mark.

Oddly enough, for all the tediously curmudgeonry in my naming
conventions article, it doesn't deal much with object names, only
variables, handlers, etc.

In code, object names usually appear after a type specifier, e.g.:

click at the loc of btn "btnSend"

...so it never occurred to me to prefix the object name itself.

This prompted me to try something I'd never used before, addressing a
control using only the "control" specifier followed by the name:

put the rect of control "btnSend"

Sure enough, it works.

I don't know why this surprises me, since I've been using ordinal
reference with "control" for years, e.g.:

repeat with i = 1 to the number of controls
get the rect of control i
...


Somehow I'd gotten the idea that the "control" specifier was limited to
ordinal references, but apparently it's not.

So thanks for your post. It prompted me to learn something new, and if
I get time I may add a section to that article on object names.

--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
LiveCode Journal blog: http://LiveCodejournal.com/blog.irv
Mark Wieder
2011-10-07 15:24:10 UTC
Permalink
Richard-
Post by Richard Gaskin
Somehow I'd gotten the idea that the "control" specifier was limited to
ordinal references, but apparently it's not.
I do that rather extensively in PowerTools because I need an object
oriented way to deal with any type of control. Since they're all
subclassed from "control" I can deal with the base class when
accessing them, then get the first word of the name to determine the
actual type.
--
-Mark Wieder
***@ahsoftware.net
René Micout
2011-10-07 15:44:43 UTC
Permalink
So thanks for your post. It prompted me to learn something new, and if I get time I may add a section to that article on object names.
Hello Richard,
This is my prefix :

-- PRÉFIXES (types des objets) :
--
---- ku = constante (unitaire)
---- kt = constante (tableau) > utiliser plutôt une custom property
--
---- vg = variable globale [stack]
---- vt = variable globale (tableau) [stack]
---- vl = variable locale [script]
---- vx = variable temporaire [handler]
---- vp = paramètre [fonctions]
---- vd = variable provisoire servant au debugage
--
---- cp = custom property
--
---- hm = handler main stack (handler situé dans le stack principal)
---- hs = handler stack (handler situé dans le script du stack)
---- hc = handler card (handler situé dans le script de la carte)
---- hg = handler group (handler situé dans le script du groupe)
---- ho = handler object (handler situé dans le script de l'objet)
--
---- fm = function main stack (fonction située dans le stack principal)
---- fs = function stack (fonction située dans le script du stack)
---- fc = function card (fonction située dans le script de la carte)
---- fg = function group (fonction située dans le script du groupe)
---- fo = function object (fonction située dans le script de l'objet)
---- db = fonction ou commande servant au debugage
--
---- btn = bouton
---- fld = field
---- grp = groupe
---- sld = slider
---- lbl = label
---- img = image
---- grc = graphic

I put also prefix before handler (and function) name (to see where it is...)

Bon souvenir de Paris
René
Pete
2011-10-07 15:55:02 UTC
Permalink
Rene,
I really like the idea of prefixes for handlers and functions that tell you
where they are located. I'd probably add a prefix for handlers in a library
as well.
Pete
Molly's Revenge <http://www.mollysrevenge.com>
Post by Richard Gaskin
So thanks for your post. It prompted me to learn something new, and if I
get time I may add a section to that article on object names.
Hello Richard,
--
---- ku = constante (unitaire)
---- kt = constante (tableau) > utiliser plutôt une custom property
--
---- vg = variable globale [stack]
---- vt = variable globale (tableau) [stack]
---- vl = variable locale [script]
---- vx = variable temporaire [handler]
---- vp = paramètre [fonctions]
---- vd = variable provisoire servant au debugage
--
---- cp = custom property
--
---- hm = handler main stack (handler situé dans le stack principal)
---- hs = handler stack (handler situé dans le script du stack)
---- hc = handler card (handler situé dans le script de la carte)
---- hg = handler group (handler situé dans le script du groupe)
---- ho = handler object (handler situé dans le script de l'objet)
--
---- fm = function main stack (fonction située dans le stack principal)
---- fs = function stack (fonction située dans le script du stack)
---- fc = function card (fonction située dans le script de la carte)
---- fg = function group (fonction située dans le script du groupe)
---- fo = function object (fonction située dans le script de l'objet)
---- db = fonction ou commande servant au debugage
--
---- btn = bouton
---- fld = field
---- grp = groupe
---- sld = slider
---- lbl = label
---- img = image
---- grc = graphic
I put also prefix before handler (and function) name (to see where it is...)
Bon souvenir de Paris
René
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
d***@aol.com
2011-10-07 15:50:45 UTC
Permalink
I rarely get to act like a pedantic jerk, especially towards a highly respected and iconic personage such as Richard Gaskin.


Not kidding about any of item 2 of line 1.


But ordinal would be 'first control". Cardinal would be "control 1"


That felt better than I thought it would.


I am sure I will regret it, though.


No kidding about item 1 of line 5.


Craig



-----Original Message-----
From: Richard Gaskin <***@fourthworld.com>
To: use-livecode <use-***@lists.runrev.com>
Sent: Fri, Oct 7, 2011 6:43 am
Subject: Re: Object Naming Conventions
Post by Pete
Thanks Mark, that's what I was looking for.
Pete
Post by Mark Wieder
Phil-
Post by Phil Davis
http://fourthworld.com/embassy/articles/scriptstyle.html
Go to the "Naming Conventions" part.
In addition to what's in Richard's writeup I tend to use the following
conventions...
Good stuff, Mark.

Oddly enough, for all the tediously curmudgeonry in my naming
conventions article, it doesn't deal much with object names, only
variables, handlers, etc.

In code, object names usually appear after a type specifier, e.g.:

click at the loc of btn "btnSend"

...so it never occurred to me to prefix the object name itself.

This prompted me to try something I'd never used before, addressing a
control using only the "control" specifier followed by the name:

put the rect of control "btnSend"

Sure enough, it works.

I don't know why this surprises me, since I've been using ordinal
reference with "control" for years, e.g.:

repeat with i = 1 to the number of controls
get the rect of control i
...


Somehow I'd gotten the idea that the "control" specifier was limited to
ordinal references, but apparently it's not.

So thanks for your post. It prompted me to learn something new, and if
I get time I may add a section to that article on object names.

--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
LiveCode Journal blog: http://LiveCodejournal.com/blog.irv

_______________________________________________
use-livecode mailing list
use-***@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Richard Gaskin
2011-10-07 16:26:19 UTC
Permalink
Post by d***@aol.com
I rarely get to act like a pedantic jerk, especially towards a highly
respected and iconic personage such as Richard Gaskin.
Not kidding about any of item 2 of line 1.
But ordinal would be 'first control". Cardinal would be "control 1"
That felt better than I thought it would.
I am sure I will regret it, though.
No kidding about item 1 of line 5.
Damn - there goes my writing career. :)

Thank you very much for the kind words, but if you've read many of the
lengthy posts I write you'll find they're often riddled with all sorts
of errors. A good friends suggests that one reason I write long posts
is that the sheer volume of materials makes it harder to spot the
mistakes. :)

But on this issue of "ordinal" vs "cardinal", I may be thinking of a
more colloquial usage than perhaps programming vernacular.

It's my understanding that "ordinal" simply refers to the order or rank
of things, such as layer numbering would impose, whether the reference
is expressed numerically or textually (i.e., it would seem to apply to
both "2" or "second").

"Cardinal" means "prime" or "most important", which had led me to
sometimes use "cardinal" when describing object references by ID, since
those are (or that is, were until very recently) immutably fixed and
therefore the most reliable form of reference.

That said, I program in relatively few languages (these days only
LiveCode and JavaScript; haven't touched a C compiler in many years, and
Lisp sadly remains on my untouched to-do list), so there may be widely
used conventions for these terms among programmers that I'm merely
ignorant of.

In my book "ignorant" is a good word, since no one knows everything so
all of us are ignorant of one thing or another, and being ignorant
simply means there's something new to learn. I'll wear that label with
pride. :)

Is this a common convention to use "cardinal" when describing numeric
ordering references, and "ordinal" only for their textual equivalent?

--
Richard Gaskin
Fourth World
LiveCode training and consulting: http://www.fourthworld.com
Webzine for LiveCode developers: http://www.LiveCodeJournal.com
LiveCode Journal blog: http://LiveCodejournal.com/blog.irv
Ken Ray
2011-10-07 03:06:18 UTC
Permalink
Post by Mark Wieder
control prefix example
---------------------------
buttons : "btn" : "btnSave"
radio buttons : "rdo" : "rdoOption1"
checkboxes : "chk" : "chkShowLineNumbers"
tab buttons : "mnu" : "mnuMainTabForm"
fields : "fld" : "fldHandlers"
labels : "lbl" : "lblSourceCode"
groups : "grp" : "grpGraphicControls"
I tend to use prefixes like this only when they aren't already abbreviations for an existing object in LC. So for example, I would use the "lbl" prefix for label field names, but not the "fld" prefix since I'm already using "fld" as the object abbreviation:

put fld "fldStuff" into tData -- is a bit redundant for me
put fld "Stuff" into tData -- ah, that's better... :D

Of course, each person has the style that works best for them, so use what you like and ditch what you don't...

;)

Ken Ray
Sons of Thunder Software, Inc.
Email: ***@sonsothunder.com
Web Site: http://www.sonsothunder.com/
Mark Wieder
2011-10-07 05:30:13 UTC
Permalink
Ken-
Post by Ken Ray
I tend to use prefixes like this only when they aren't already
abbreviations for an existing object in LC.
Absolutely. I also quite often use graphic images as buttons, so I'll
go

hide graphic "btnSaveMe"

and there the "btn" reminds me of the purpose of the graphic.
--
-Mark Wieder
***@ahsoftware.net
Mark Wieder
2011-10-07 05:53:11 UTC
Permalink
Ken-

<g> that was supposed to read:

"Of course, each person has the style that works best for them, so use
what you like and ditch what you don't..."
Post by Mark Wieder
Absolutely.
--
-Mark Wieder
***@ahsoftware.net
René Micout
2011-10-07 08:28:28 UTC
Permalink
Mark,
I do almost the same...
René
Post by Mark Wieder
Phil-
Post by Phil Davis
http://fourthworld.com/embassy/articles/scriptstyle.html
Go to the "Naming Conventions" part.
In addition to what's in Richard's writeup I tend to use the following
conventions. Mostly just a carryover from other development
environments since they don't really do much, but they tend to trigger
the same neuron activity so it makes it easier for me to conceptualize
control prefix example
---------------------------
buttons : "btn" : "btnSave"
radio buttons : "rdo" : "rdoOption1"
checkboxes : "chk" : "chkShowLineNumbers"
tab buttons : "mnu" : "mnuMainTabForm"
fields : "fld" : "fldHandlers"
labels : "lbl" : "lblSourceCode"
groups : "grp" : "grpGraphicControls"
The only other rule of thumb I have is to keep object names one word
rather than having spaces in the middle. And of course, that rule,
like any other rule, was made to be broken when needed.
--
-Mark Wieder
_______________________________________________
use-livecode mailing list
http://lists.runrev.com/mailman/listinfo/use-livecode
Francis Nugent Dixon
2011-10-07 11:37:30 UTC
Permalink
Hi from Beautiful Brittany,

Pete, there has been a thread on this subject several
times, but I'm not against seeing it again.

Whatever you do, use a prefix to define ALL your objects,
but find a rule that suits you. Don't use a suffix, I'm
sure you will regret it.

I use a two-letter indicator (but each to his own poison !)
- only 2 letters (CAPS) and not 3, like Mark !

Custom Properties CPxxx
Global Variables GVxxx
Local Variables LVXXX
Fields Myxxx
Labels LBxxx
Buttons BTxxx
Groups GPxxx
Functions DFxxx

I also deliberately use "repeat" variables : I, J, K, etc.
(old Fortran rules, but habits die hard !) It also has the
advantage of being crystal-clear !

It may take a little time to adjust to your new rules
but, if you come back to your scripts in 6 months, you
will be glad you invented them.
I agree with Mark about length of names - one word is enough !

Best Regards

-Francis
J. Landman Gay
2011-10-07 17:39:26 UTC
Permalink
Post by Francis Nugent Dixon
Whatever you do, use a prefix to define ALL your objects,
I never do, I don't see any advantage, and for me it makes my scripts
harder to read. It's easy to see what type an object is if you forget.
In fact, the only consistent naming scheme I use for objects is "lbl" in
a field name, so that I can skip label fields in repeat loops.

We're all different. I really doubt any two of us codes the same way. :)
--
Jacqueline Landman Gay | ***@hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Mark Wieder
2011-10-08 01:05:27 UTC
Permalink
Jacque-
for me it makes my scripts harder to read.
Well, that's the purpose of a scripting convention. If what you're
doing makes it easier for you to read your scripts then you're doing
things the right way.
We're all different. I really doubt any two of us codes the same way. :)
I don't even code the same way twice. I'm always refactoring things as
I learn more or come across clever hacks to speed things up or make my
code more readable or something.
--
-Mark Wieder
***@ahsoftware.net
Loading...