This thread was started discussing removal of xdata but focused on the handling of exceptions, so I moved it to its own thread.
![]() |
|
![]() |
|
![]() |
|
![]() |
This thread was started discussing removal of xdata but focused on the handling of exceptions, so I moved it to its own thread.
Last edited by peter; 2014-02-18 at 04:14 PM.
AutomateCAD
Peter, my friend -
Words have meaning... These statements, and those made above, are mutually exclusive.
We both share an appreciation for, and interest in extending, LISP. So let's do exactly that by putting out the most accurate information, and quality examples we can.
I know you're very passionate about this topic, and I want for this initiative to be successful as well... Please do not take my comments & corrections personally, as they're intended to help the reader.
Equally important is not letting new developers incorrectly believe that they don't need to account for exception handling in their LispFunction Methods, as I once (stubbornly) believed, and Gile was kind enough to educate me (I owe him a few bottles of Champagne for all that he's taught me)... Properly validating both the number, and type of parameters supplies with a given LispFunction Method's ResultBuffer is essential.
An excerpt from one of my many, many learning moments in .NET development (in this instance, specifically LispFunction Method) best practices:
Separately, have you considered implementing a 'using' statement in your Transaction call? Why opt for a Document Transaction, when the entity data is Database resident?
Cheers
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
It is my opinion that most errors can be handled by the programmer.
In the style I prefer, I choose to make sure the arguments are the correct type.
Rather than throw an exception for a number instead of a string, I just use the tostring and convert whatever it is to a string.
I also use case statements that ignore extra arguments...
and have been working on a general solution for converting typedvalue result buffers to arguments and back.
I also like to allow the user to have different numbers of arguments, including 0 if possible.
I also manage the errors by checking success at the end of a function by returning nothing or nil for failure and a value, true, or a T_Atom at the end for success.
I handle the exception in the routine rather than have a lot of error statements mess up the command prompt.
I recognize that you prefer to have exception feedback and I think that is a valid way of doing it too.
I do think for demonstrating basic functionality, adding exception handling is more complicated than handling the errors in the flow.
So for simple examples I prefer to not include them.
In your posts I have no problem with you demonstrating them and including them in your examples... It is just another way of doing it.
AutomateCAD
If you look at my lisp code I like to use the 'and' statement to handle errors
This style which I prefer... it immediately drops out if an error is detected, but it doesn't crash the program.Code:(if (and (function1 "test") (setq xyz (function2 "test")) (errortrap (quote (/ 1 0))) etc... ) (princ "\nSuccess!!!") (princ "\nOops something didn't work - handle the error") )
I hope you understand the reasoning behind the 'nil' return value now.
I just continue on in my loop or whatever.
I am always contemplating what it means if I encounter an error and what it will do to the results of the routine.
p=
AutomateCAD
I would like to explore ideas that would move the handling of exceptions out of base functions into an encapsulated function that could be called from the base function in a single function call.
Exceptions do provide useful information to the programmer, but putting all of the exception functionality in all of your base functions is redundant and IMHO clouds the simplicity of a base function.
I have thought of using xml to transfer all of the information to the error exception handler.
Like if I pass the arguments, required data types, and default values to the exception handler, it should be able to check all of them and create the error messages if required and return the data values back to the base function without messing up the code.
That way a single function could handle all of the argument exceptions.
I would be interested in looking at anyone elses code that has tried to do that.
p=
AutomateCAD
It seems that the original, incorrect statements made on the inability to remove XData with vanilla LISP (which prompted me to participate in the first place) have not been included here, when moving these posts to a new thread... Please restore those as well for clarity / context.
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
I left the comments on the xdata post in the thread with the xdata and split the thread on exceptions to here.
They seemed to be two different subjects and this subject justified its own thread.
p=
AutomateCAD
This post must have come in while I was typing....
I appreciate the motivation, and strongly encourage you to continue exploring how to extend LISP. You're very talented, and creative. As a wiser man than I once said, 'I prefer clarity to agreement'. I'd like to believe that we have more in common than not.
Cheers
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000
I was thinking of something similar. I.e. a class working in the opposite direction as the ObjectToTypedValue class in the other thread. This should convert the result buffer into its object(s) - perhaps some list/array.
While it's at it, it should also check to see if the correct types are found in the resbuf as was expected. Unfortunately this last aspect is very complex to achieve (especially for a general purpose class). There may be infinite combination possibilities, e.g. some argument might be allowed to be more than one type (e.g. int and real). Another argument might be allowed to be omitted. You'd need some way of telling this ResBuf->ObjectList class just what you're expecting so it can check the input against those rules.
I'm really struggling to understand this; I'd be remiss if I didn't also point out the irony here.
Some have all but balked at the suggestion that basic Exception handling be implemented in the LispFunction Methods being offered, yet somehow a new, indeterminably complex Class structure to handle each-and-every-single-possible Exception potentiality (which would most assuredly be longer than one page, of unknown font size, font style, and page margins, etc.) is worthwhile?
Would it not be preferable to simply implement basic code logic to throw one or more basic *LispExceptions (i.e., TooFewArgs, TooManyArgs, ArgumentType, etc.), in addition to any custom *LispException Types that derive from same, in order to scrub a given LispFunction Method's ResultBuffer for the required or allowed argument(s)?
Never mind the fact that even if such an all-inclusive Exception handling Class existed, you'd still need sufficient code logic to feed this Type's constructors the appropriate parameters (where you'd normally just throw the aforementioned *LispExceptions).
Last edited by BlackBox; 2014-02-20 at 02:35 PM.
"How we think determines what we do, and what we do determines what we get."
Sincpac C3D ~ Autodesk Exchange Apps
Computer Specs:
Dell Precision 3660, Core i9-12900K 5.2GHz, 64GB DDR5 RAM, PCIe 4.0 M.2 SSD (RAID 0), 16GB NVIDIA RTX A4000