Author Topic: Why is Autolisp variable naming so terrible?  (Read 6827 times)

0 Members and 1 Guest are viewing this topic.

Jeff H

  • Needs a day job
  • Posts: 6150
Why is Autolisp variable naming so terrible?
« on: November 21, 2011, 04:04:38 PM »
This is not aimed at anyone particular and have noticed it done by many of the good ones here.

I was just wondering why and does it ever cause problems naming your variables l, a, s, d, m, etc....
 
I do not see how you can keep up with them or do the one letter variables usually represent the same type from program to program?
 

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Why is Autolisp variable naming so terrible?
« Reply #1 on: November 21, 2011, 04:12:08 PM »
I use the name for the list L, P for the point, I refer to other variables as given. Typically, the local variables used in a number less than 1000 lines of code, I use only one letter. If I have several identical within the meaning of variables, such as two points, I add a number, for example P1, P2 ... Most often, I use the letters that are easy to press with your left hand - right more often occupied by the mouse.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Why is Autolisp variable naming so terrible?
« Reply #2 on: November 21, 2011, 04:13:12 PM »
<imo> When it's done by senior members I believe it's (a) probably a carry over of old habits formed when even variable name length (other programming platforms, not AutoLISP) cut into available programming memory, or (b) typing frugality, or (c) an unfortunate misconception that brevity is king. Concise is nice but not at the expense of algorithm clarity. Lucid > brevity. </imo>
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Why is Autolisp variable naming so terrible?
« Reply #3 on: November 21, 2011, 04:16:05 PM »
<imo> When it's done by senior members I believe it's (a) probably a carry over of old habits formed when even variable name length (other programming platforms, not AutoLISP) cut into available programming memory, or (b) typing frugality, or (c) an unfortunate misconception that brevity is king. Concise is nice but not at the expense of algorithm clarity. Lucid > brevity. </imo>
When I took programming in high school, the teacher made a comment about short variable and command names because it was memory and that typing wasn't as easy on the older mechanical keyboards, thus, commands/functions were kept at only a few letters. Would you agree/disagree with that?
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Why is Autolisp variable naming so terrible?
« Reply #4 on: November 21, 2011, 04:17:46 PM »
Would you agree/disagree with that?

yes
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Why is Autolisp variable naming so terrible?
« Reply #5 on: November 21, 2011, 04:19:16 PM »
Would you agree/disagree with that?

yes
arg, poor wording. Do you agree or disagree with my above question?  :-P
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Why is Autolisp variable naming so terrible?
« Reply #6 on: November 21, 2011, 04:22:45 PM »
<imo> When it's done by senior members I believe it's (a) probably a carry over of old habits formed when even variable name length (other programming platforms, not AutoLISP) cut into available programming memory, or (b) typing frugality, or (c) an unfortunate misconception that brevity is king. Concise is nice but not at the expense of algorithm clarity. Lucid > brevity. </imo>

my code
Code: [Select]
(defun test (l / f)
  (defun f (a l) (if a (* (atoi (caddr a)) (f (assoc (cadr a) l) l)) 1))
  (mapcar (function (lambda (a) (append a (list (itoa (f a l)))))) l)
)

here
L - list
F - function
A - more info
The code is small and intuitive
If it is to increase the length and clear variables, it will be worse than to read and understand! It is a small amount of code allows you to see the algorithm at once.

PS. I think that variables should always be shorter function names. Otherwise, the variables will be obscure the code...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Why is Autolisp variable naming so terrible?
« Reply #7 on: November 21, 2011, 04:24:52 PM »
arg, poor wording. Do you agree or disagree with my above question?  :-P

Not trying to be more of a dick than my usual cantankerous self ... you quoted my first post but I wonder if you actually read it. Subtitle: I believe I answered your question in advance. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Why is Autolisp variable naming so terrible?
« Reply #8 on: November 21, 2011, 04:28:45 PM »
Do you agree or disagree with my above question?  :P
I choose the correct one.
 
Does the length of a variable's name affect memory or does it get bound to the memory address or something other arbitrary value?

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Why is Autolisp variable naming so terrible?
« Reply #9 on: November 21, 2011, 04:31:18 PM »
All the variables, it is only a reference to the storage location information.
The size of the variable name, it is easy to read code and the size of the source file.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Why is Autolisp variable naming so terrible?
« Reply #10 on: November 21, 2011, 04:33:07 PM »
arg, poor wording. Do you agree or disagree with my above question?  :-P

Not trying to be more of a dick than my usual cantankerous self ... you quoted my first post but I wonder if you actually read it. Subtitle: I believe I answered your question in advance. :)
Dammit! LoL
Do you agree with my above question about lengths of command names and stored variables?  :lol:
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Why is Autolisp variable naming so terrible?
« Reply #11 on: November 21, 2011, 04:33:19 PM »
ElpanovEvgeniy my friend, I have always admired your intellect and acuity, but I cannot agree that (generally speaking, not the simplistic example) "the code is intuitive" or that "if it is to increase the length and clear variables, it will be worse than to read and understand". As we are both of strong opinions we will have to disagree upon the manner in which food is spiced while agreeing we both love to cook. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Why is Autolisp variable naming so terrible?
« Reply #12 on: November 21, 2011, 04:40:46 PM »
Just seems eaiser to read
startPoint
endPoint
vs.
p1
p2
 
I am not good at smart people stuff so that might have something to do with it.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Why is Autolisp variable naming so terrible?
« Reply #13 on: November 21, 2011, 04:43:36 PM »
took the sample code here: http://www.theswamp.org/index.php?topic=31524.0
my variant variable naming
Code: [Select]
(defun test (l / f)
  (defun f (a l)
    (if a
      (* (atoi (caddr a)) (f (assoc (cadr a) l) l))
      1
    )
  )
  (mapcar (function (lambda (a) (append a (list (itoa (f a l)))))) l)
)

variables used in the code xianaihua
Code: [Select]
(defun test (bom_lst / SumPartCounts)
  (defun SumPartCounts (assembly bom_lst)
    (if assembly
      (* (atoi (caddr assembly)) (SumPartCounts (assoc (cadr assembly) bom_lst) bom_lst))
      1
    )
  )
  (mapcar (function (lambda (assembly) (append assembly (list (itoa (SumPartCounts assembly bom_lst))))))
          bom_lst
  )
)

Shorter code, it seems to me clearly.
Maybe I'm reading the very structure of the program and give it more attention than the meaning of data variables.

I read that programmers use Lisp, do not use flow charts of the program. For LISP programmers to program itself this is a scheme.
Perhaps that's why I do not need long variable names on the short code.
ps. a long code, I give a long and meaningful names to variables, which can be used rarely and far between.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Why is Autolisp variable naming so terrible?
« Reply #14 on: November 21, 2011, 04:45:53 PM »
At the risk of pointing out the obvious, there is a balance, that admittedly, varies from person to person, with regards to economy vs lucidity. I've no problem with p1, p2 or even i for that matter, when it's an iterator etc., but when a code snip is comprised entirely of single letter variables I find I easily glaze as the code turns into one mess of an ascii stream, though the lack of carriage returns / white space is another contributing factor. Oh crap, another can of worms opened ...
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst