Author Topic: Variable Naming Convention  (Read 4564 times)

0 Members and 1 Guest are viewing this topic.

mmason

  • Guest
Variable Naming Convention
« on: May 19, 2009, 10:26:09 PM »
My wandering mind is wondering this evening as I was doing my usual stumbling through some happy vlisp.  It occurred to me that for myself and maybe others a discussion regarding variable names might be a good thing.

I see many different methods people use when naming variables.  Special characters, prefixes and such.  Which begs the question; Is there some sort of semi-standard or (somewhat) universally accepted naming convention for variables in a lisp program?

Some examples might be:
*active-document*, SelectedLayer$, ^IterationList, eb:BlockCollection (where 'eb:' ties the variable to a function such as 'EraseBlock').

Would one format be used for global variables and another for locals?  Another format for collections?

Ideas?  Opinions?

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Variable Naming Convention
« Reply #1 on: May 19, 2009, 11:00:54 PM »
*big* topic, *many* considerations.

no convention just personal preferences and current uses/structures.

sleep needed.



*lol*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Variable Naming Convention
« Reply #2 on: May 20, 2009, 12:21:08 AM »
Welcome to The Swamp mlm.

I too am off to bed, see you tomorrow.  ZZzzzz.....
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Chuck Gabriel

  • Guest
Re: Variable Naming Convention
« Reply #3 on: May 20, 2009, 07:33:05 AM »
If you see an asterisk at the beginning and end of a variable name, there is a good chance it is a global variable.  I've also seen the prefix (like the eb: you mentioned) used on globals to identify what function they belong to.  I can see how that would ease some maintenance woes.  Other than that, what I've seen seems pretty arbitrary.

Oh yeah, welcome to the swamp.
« Last Edit: May 20, 2009, 07:36:39 AM by Chuck Gabriel »

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Variable Naming Convention
« Reply #4 on: May 20, 2009, 07:55:27 AM »
I normally use the format:

<function_name> : <variable_name>

for my globals, (and sometimes chuck a few special chars in there for good measure), but as for local names...

ent  = ename
ss   = selection set
elst  = entget return
obj  = vla-object
cObj = curve object...

I get lazy though...

mmason

  • Guest
Re: Variable Naming Convention
« Reply #5 on: May 20, 2009, 08:09:05 AM »
*big* topic, *many* considerations.

no convention just personal preferences and current uses/structures.

sleep needed.



*lol*
Welcome to The Swamp mlm.

I too am off to bed, see you tomorrow.  ZZzzzz.....


OK, so we've got 7 seein' stars and at the end of the day, Mr. B likes some Z's  :wink:

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Variable Naming Convention
« Reply #6 on: May 20, 2009, 08:12:41 AM »
I've always been kinda partial to the VB naming conventions - although, admittedly, I don't always stick to it.   :|

http://support.microsoft.com/kb/110264
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

mmason

  • Guest
Re: Variable Naming Convention
« Reply #7 on: May 20, 2009, 08:18:16 AM »
I get lazy though...

I hear that.  In the old days, we did the ol'...
(if (= (+ n1 n2) x) (princ str))

Now I tend to use more like...
(if (= (+ ThisNumberThatIPulledOutOfSomeWhere ThatNumberThatIGotSomeWhereElse) SomeNumberSomeOneToldMeWasWhatIShouldUse) (princ SomeSillyConvolutedMessageToTheUser))

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Variable Naming Convention
« Reply #8 on: May 20, 2009, 08:25:56 AM »
I have adopted a more descriptive like the later mlm demonstrated.

I tend to shy away from global variables however if needed, i prefix them with a special char.


TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

mmason

  • Guest
Re: Variable Naming Convention
« Reply #9 on: May 20, 2009, 09:17:21 AM »
I've always been kinda partial to the VB naming conventions - although, admittedly, I don't always stick to it.   :|

http://support.microsoft.com/kb/110264

Now, this makes sense!  Those of us in varying degrees of migrations to and intergrations with .NET along with AutoLISP could employ a somewhat similar methodology to variable naming.  That way the LISP'ers and the .NET'ers could (sort of) understand each other.

Wait!  But then Matt and I would have to start being consistent!?  I'm not sure my wandering mind is up to that task.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Variable Naming Convention
« Reply #10 on: May 20, 2009, 10:27:01 AM »
I've always been kinda partial to the VB naming conventions - although, admittedly, I don't always stick to it.   :|

http://support.microsoft.com/kb/110264

Now, this makes sense!  Those of us in varying degrees of migrations to and intergrations with .NET along with AutoLISP could employ a somewhat similar methodology to variable naming.  That way the LISP'ers and the .NET'ers could (sort of) understand each other.

Wait!  But then Matt and I would have to start being consistent!?  I'm not sure my wandering mind is up to that task.
What if we were consistently inconsistent?  That way, we'd still be consistent, but on a different level.    :lol:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

SEANT

  • Bull Frog
  • Posts: 345
Re: Variable Naming Convention
« Reply #11 on: May 20, 2009, 11:07:39 AM »
Wait a minute; I thought the best way to bolster job security, as well as encourage a relaxed work environment, was to give variables friendly names like Fred, Helga, Spanky, etc.  Isn’t it also recommended to set the same variable to several different names, as a variety enhancement to alleviate boredom?

I actually stole this concept from a hilarious list somewhere that encourages sensible coding techniques by expounding the “virtues” of the opposite.  I don’t suppose anyone has recalls that link?
Sean Tessier
AutoCAD 2016 Mechanical

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Variable Naming Convention
« Reply #12 on: May 20, 2009, 11:32:50 AM »
I don’t suppose anyone has recalls that link?

I think this is it
« Last Edit: May 20, 2009, 11:42:26 AM by CAB »
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Variable Naming Convention
« Reply #13 on: May 20, 2009, 11:37:56 AM »
I don’t suppose anyone has recalls that link?

I think this is it.

ahah not funny... I was stuck on that for about 5 mins... keeps jumpin round..
« Last Edit: May 20, 2009, 11:41:38 AM by CAB »

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Variable Naming Convention
« Reply #14 on: May 20, 2009, 11:39:37 AM »
I don’t suppose anyone has recalls that link?

I think this is it.

ahah not funny... I was stuck on that for about 5 mins... keeps jumpin round..
Like I said... I THINK this is it.  I wasn't sure.   :roll:
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Variable Naming Convention
« Reply #15 on: May 20, 2009, 11:44:39 AM »
I didn't find it a bit funny.  :-(
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

mmason

  • Guest
Re: Variable Naming Convention
« Reply #16 on: May 20, 2009, 11:51:08 AM »
Wait a minute; I thought the best way to bolster job security, as well as encourage a relaxed work environment, was to give variables friendly names like Fred, Helga, Spanky, etc.  Isn’t it also recommended to set the same variable to several different names, as a variety enhancement to alleviate boredom?

There is also the paranoid programmer's pre-compiled method:

(if (= (+ &*^%$%$#@^&^ !@!#@$%$#%&) &*^%^$@#@$$!*) (princ (strcat %$^#&*!@# ", Spanky"))

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Variable Naming Convention
« Reply #17 on: May 20, 2009, 12:05:28 PM »
Wait a minute; I thought the best way to bolster job security, as well as encourage a relaxed work environment, was to give variables friendly names like Fred, Helga, Spanky, etc.  Isn’t it also recommended to set the same variable to several different names, as a variety enhancement to alleviate boredom?

I actually stole this concept from a hilarious list somewhere that encourages sensible coding techniques by expounding the “virtues” of the opposite.  I don’t suppose anyone has recalls that link?


I did find this: http://www.theswamp.org/index.php?topic=1786.msg22798#msg22798
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

SEANT

  • Bull Frog
  • Posts: 345
Re: Variable Naming Convention
« Reply #18 on: May 20, 2009, 12:18:37 PM »
Sean Tessier
AutoCAD 2016 Mechanical

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Variable Naming Convention
« Reply #19 on: May 20, 2009, 12:57:38 PM »
Wait a minute; I thought the best way to bolster job security, as well as encourage a relaxed work environment, was to give variables friendly names like Fred, Helga, Spanky, etc.  Isn’t it also recommended to set the same variable to several different names, as a variety enhancement to alleviate boredom?

I actually stole this concept from a hilarious list somewhere that encourages sensible coding techniques by expounding the “virtues” of the opposite.  I don’t suppose anyone has recalls that link?


I did find this: http://www.theswamp.org/index.php?topic=1786.msg22798#msg22798


HAHahahah that is brilliant CAB   :lol: