View Full Version : Readability and Stability
peter
2017-06-21, 10:48 PM
I just thought I would ask the question about readability and stability in code.
I found writing code professionally, that the customer doesn't care why code crashes, just I hear about the frustration.
I have always tried to write stable code but error checking and trapping is mush more important now.
Also with large libraries (several hundred functions) it has made me much more aware of the issue of maintenance.
If I cannot figure out what an expression or function does immediately it needs better naming and notes.
Personally I do not use ;setq end type notes in my code because to me it is like switching from Spanish to English in the same sentence.
I like VERY descriptive variable and function naming.
I like short simple functions that do specific things with simple names.
I like the noun first verb last function naming.
I separate the command line functions in a library from the generic functions.
I have libraries of general functions that I load with a function.
I use LISP shorthand functionality... (I rewrote lisp to include errortrapping and remove the russian prefixes like vla-get...)
I have a header on top of every file and a lisp browser to search for functions...
I like the reddick naming convention for variables.
I try to do the same process every time I write code to make it absolutely easy to read and easy to maintain.
I would be interested in feedback and your own ways of achieving readability and stability.
P=
Tom Beauford
2017-06-22, 11:32 AM
Thank you for the code you've shared over the years, but you need to provide links or a Peter's web page with details.
Lisp browser to search for functions? http://help.autodesk.com/view/ACD/2018/ENU/?guid=GUID-4CEE5072-8817-4920-8A2D-7060F5E16547
Reddick naming convention for variables? https://ss64.com/access/syntax-naming.html
I use descriptive variable, function, and lsp file naming. Haven't tried the Prefix and Suffix stuff though.
dgorsman
2017-06-22, 06:42 PM
Oh *gag* - including value type in the variable name... years ago when variable names were deliberately short , yeah - intA1, strNm3, etc. But if a variable is named reasonably well that's redundant. A "loop_counter" is an integer, not a string; a "max_distance" is a double not a short; a "description" is a string not a double; a "line_ent" is an entity, not a value.
BIG-AL
2017-06-24, 05:06 AM
Writing lisp for around 30+ years using variable names that make sense is probably a 1st priority making reading easier, I always have points as p1 p2 or pt1 etc I noticed some code with weird naming *sdf* and always worry that it will not work compared to using alphabet I have started more recently making my defuns AH:xxxx so dont match some one else naming. Like Peter I believe in library use and have recently converted a lot of routines that ask for input using library dcl's that generate coding on the fly. Two lines in code 1st check if loaded 2nd actual call sequence. Most code now is also demand loaded. Most of the code I post is in response to a singular request so have to keep adding some extra defuns form the library. More recent have just started adding extra as attachments.
Tom Beauford
2017-06-25, 11:42 AM
I rarely use global variables, but do weird the descriptive names when I do to avoid conflicts with other code by adding characters like *±°×|↑↓↕ before and after them.
peter
2017-06-25, 10:05 PM
I don't have a web page, but I have posted over 900 times to this forum and to the guilds at least once a day for several years.
I started coding LISP in 1986 and have been doing it daily since.
I have written my share of spaghetti code...
Then I learned structured programming and started creating reuseable functions.
The functions I name like AttributeValue or AttributeValuePut (the get and put of the save object)
I found the noun first verb second made my libraries (when alphabetized) easy to maintain.
I also add errortrap expressions to methods and properties that may cause an error.
I also design all functions to return T or a value for success and nil for failure.
As far as lisp variables I too avoid global variables except in the case of recursive functions and of course DBX routines.
For my naming convention prefixes I use
col = collection (sometimes I just use obj for collections)
ent = entity
lst = list
lstOf = list (of sublists)
obj = object
sng = single precision real number
ss = selection set
str = string
I call an entsel return value lstSelection
ssSelections a selection set
entSelection or entItem an entity
objSelection or objItem a vla-object
strFullName as the fullname of a file
strFileName as the filename of a file
lstObjects a list of objects (while I use a lot when I convert a selelction set or collection into a list of objects)
intCount a counter
etc...
I would ask you all if you read my code is it clear when the functions do and what the variables hold?
When I post to the group I write the base code and then go get the library functions to add to the post that do specific things.
Most of my functions are super short but I have to expand them because you all do not have my libraries.
I have hundreds of code samples here at AUGI for you all to review.
I just wanted to help those new to lisp programming to not only think of making it work... but stable and easy to maintain and read
Tom Beauford
2017-06-26, 12:39 PM
Hard to imagine such a gifted coder without a web page, but there's many ways of sharing your code here where we can find it. Add a link to all your posts to your Signature peter's posts (http://forums.augi.com/search.php?searchid=865744) and a link to a post for needed library functions for the lisp you post so you don't have to expand them.
Another way would be writing an article for AUGI on coding with descriptions and links to coding examples on the Lisp Forum. Keep in mind I doubt if much of you code I've saved of your's many years ago could be found on AUGI now.
Lots of long time followers here who would love to access your deep well of code and from the amount of replies here most of the newer coders aren't sure what this thread is about.
I use Altervista for free web hosting my page: http://beauford.altervista.org/ which is linked in my signature below where the two sections with the dark gray background (same as my AutoCAD screen) are all AutoCAD related. I'd be willing to help you create a web page if you would like, since it would be a nice lisp resource to have.
peter
2017-06-27, 03:44 PM
This thread is like VisualLISP 501 or a graduate level understanding.
I choose to support AUGI and post here.
Part of the reason AUGI has done well over the years is members chose to post here.
I am a moderator/administrator here and I could teach LISP on a closed thread.
What level should I start?
If I teach a very basic class ( like expression level training) it could take a long time to get tot the really useful code and it may become boring to more advanced coders.
If I start assuming a very basic understanding, you get to the good stuff faster but you might lose some of the newbies.
I guess I would be willing to teach a class (or classes) HERE to the membership here if there is an interest.
Chime in and let me know if you are interested in participating and where you think I should start or topics I could post on.
P=
Tom Beauford
2017-06-27, 05:13 PM
I've seen too many basic lisp classes from ATP here to all over the web. Assume at least an intermediate understanding of lisp. Using an open forum where more experienced users could aide you in assisting those who need help keeping up like in the regular lisp forum.
It should be broken in to segments like error management, recursion, dialog boxes, etc… that would be archived with routines so we could reference them years from now if we needed.
Afterwards a beginner class on switching to NET would be nice as well.
peter
2017-06-27, 07:08 PM
I IM'ed to Opie and he is good with stickie classes with a linked discussion forum.
That way the class is separated from the discussion.
I would probably present an AutoLISP 101 and series for the newbies...
A more advanced VisualLISP 101 and series at the same time.
I wont waste my time unless I get involvement, but I do not have trouble sharing my expertise as long as it is appreciated.
I also understand that everyone has their own style and styles evolve over time...
I will teach my style.
So far I have two interested participants of different levels.
All you lurkers who are interested chime in.
What would you like to learn?
Tom Beauford
2017-06-27, 07:19 PM
Looking forward to both classes. A section on reactors would be nice as well.
peter
2017-06-27, 09:54 PM
One thing about programming lisp is it is fun to figure it out by yourself without being taught.
If there is enough interest...
Chime in if you all are interested.
P=
devitg.89838
2017-06-28, 01:02 PM
Hi Peter. Wellcome your help .
I start Lisp´ing about at last 90´s .
My first error was to name a variable with O o , to name Orig has to be 0 0 0 , the when typing put 0rig , since it I name it URIG .
I name all variable with it´s meaning .
BOTTOM HEIGHT SIDES TAPPER-ANG THICK TOP URIG VAR-LIST
I use defun , or subroutines , and also name it´s meaning , and with the needed argument to send.
&-line/pt1-pt2
(DEFUN &-LINE/P1-P2 (P1 P2 / PA PB)
(IF (= (TYPE P1) 'LIST)
(SETQ PA (VLAX-3D-POINT P1))
(SETQ PA P1)
)
(IF (= (TYPE P2) 'LIST)
(SETQ PB (VLAX-3D-POINT P2))
(SETQ PB P2)
)
(VLA-ADDLINE MODEL PA PB)
)
;;************************************************************
& for ADD ,
And first all a INIT-VL defun to load all VLXXX
The Vlax-dump , is a must
;;***********************************************************************************
(DEFUN INIT-VL () ; 25-03-2017
(VL-LOAD-COM)
(SETQ ACAD-OBJ (VLAX-GET-ACAD-OBJECT)) ;_ el programa ACAD
(SETQ ADOC (VLA-GET-ACTIVEDOCUMENT ACAD-OBJ)) ;_ el DWG que esta abierto-
(SETQ MODEL (VLA-GET-MODELSPACE ADOC))
(SETQ SELECTIONSETS (VLA-GET-SELECTIONSETS ADOC))
(SETQ PAPER (VLA-GET-PAPERSPACE ADOC))
(SETQ VIEWPORT-COLL (VLA-GET-VIEWPORTS ADOC))
(SETQ LAYOUT-COLL (VLA-GET-LAYOUTS ADOC))
;;;(vlax-dump-Object adoc T)
(SETQ APPA (VLA-GET-APPLICATION ADOC))
(SETQ UTILITY (VLA-GET-UTILITY ADOC))
(SETQ ACAD-PREFERENCE (VLA-GET-PREFERENCES ACAD-OBJ))
;(dump ACAD-PREFERENCE)
(SETQ TEMP-FILE (VLA-GET-FILES ACAD-PREFERENCE))
(SETQ TEMPFILEPATH (VLA-GET-TEMPFILEPATH TEMP-FILE))
(DUMP TEMP-FILE)
(SETQ PREFERENCE-DISPLAY (VLA-GET-DISPLAY ACAD-PREFERENCE))
(SETQ GRAPHICSWINMODELBCK-GROUND (VLA-GET-GRAPHICSWINMODELBACKGRNDCOLOR PREFERENCE-DISPLAY))
(SETQ LAY-COLL (VLA-GET-LAYERS ADOC)) ;_ all layers
(SETQ TEXT-STYLES-COLL (VLA-GET-TEXTSTYLES ADOC))
;;;(vla-item text-STYLES-coll 1)
(SETQ BLOCK-COLL (VLA-GET-BLOCKS ADOC))
(SETQ DIMSTYLE-COLL (VLA-GET-DIMSTYLES ADOC))
(SETQ VERS$ (ITOA (ATOI (VLA-GET-VERSION APPA))))
;;; (setq vers# (atoi (getvar "ACADVER")))
;;; (setq vers$ (itoa (fix vers#)))
(SETQ ACAD-AC-ACM (STRCAT "AutoCAD.AcCmColor." VERS$))
(SETQ ACMCOL (VLAX-INVOKE
(VLAX-GET-ACAD-OBJECT)
'GETINTERFACEOBJECT
ACAD-AC-ACM
)
) ;_ acmcol
;_ all dictionaries
(SETQ PREF (VLA-GET-PREFERENCES APPA))
(SETQ DISPLAY (VLA-GET-DISPLAY PREF))
(VLA-PUT-HISTORYLINES DISPLAY 1000)
(SETQ MAX-WIN (VLA-GET-MAXAUTOCADWINDOW DISPLAY))
(VLA-PUT-MAXAUTOCADWINDOW DISPLAY :VLAX-TRUE)
(SETQ SUPPORT-PATH (VLA-GET-SUPPORTPATH (VLA-GET-FILES (VLA-GET-PREFERENCES (VLAX-GET-ACAD-OBJECT)))))
;;;(arx)
(IF (= (CAR (MEMBER "acetutil.arx" (ARX))) "acetutil.arx")
(PRINC (STRCAT "acetutil.arx" " esta cargado"))
(PROGN
(ARXLOAD "acetutil.arx" "no se cargo")
(PRINC (STRCAT "acetutil.arx" "..se ha cargado"))
)
)
;;;(if (FINDFILE "acetauto.lsp")
;;; (load "acetauto.lsp")
;;;(alert "You need \n acetauto.lsp")
;;; )
;;;(c:acetauto)
"init loaded"
) ;_ (init-vl)
The Vlax-dump , is a must
;;************************************************************************************************************
(DEFUN DUMP (OBJ) ;-001
(IF (= (TYPE OBJ) 'ENAME)
(SETQ OBJ (VLAX-ENAME->VLA-OBJECT OBJ))
)
(VLAX-DUMP-OBJECT OBJ T)
)
;;************************************************************************************************************
I work allways with the same lisp , I name it VL-BASE xxx-00 description user and forum
And change the XXX at any new LISP I do
Up now I have about 600 done.
It is as my toolbox
If I made a new one keep it for further use.
After it work , I keep the needed defun and new work to be a new LISP , I sent to whom I help.
Other naming is
;;*//*/*/*/*/*/*/*/*/*/*/*/*/**/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*
(DEFUN G-LAYER/obj (OBJ)
(IF (= (TYPE OBJ) 'ENAME)
(SETQ OBJ (VLAX-ENAME->VLA-OBJECT OBJ))
)
(VLA-GET-LAYER OBJ)
)
And P-
To put
;;;;;-*******************************************************************************************************
And
;;************************************************************
(DEFUN P-LAYER/OBJ-NAME (OBJ LAY)
(IF (= (TYPE OBJ) 'ENAME)
(SETQ OBJ (VLAX-ENAME->VLA-OBJECT OBJ))
)
(VLA-PUT-LAYER OBJ LAY)
)
;---------------------------------------------------------------------------------------------------------
That's my two cents
CEHill
2017-06-28, 01:57 PM
We are ready!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.