I think I'm missing something that ought to be obvious - again...

Discussion in 'AutoCAD' started by David Kozina, Apr 21, 2004.

  1. David Kozina

    David Kozina Guest

    Tom,

    What I found rather interesting was that my original code used:

    (if X
    (cond
    (A)
    (C)
    )
    (cond
    (B)
    (C)
    )
    )

    Whereas the solution you came up with went:

    (cond
    ((if X
    (A)
    (B)
    )
    )
    (C)
    )

    *Almost* the same, but inside out, if you will.

    Best regards,
    David Kozina
     
    David Kozina, Apr 22, 2004
    #21
  2. David Kozina

    Tom Smith Guest

    *Almost* the same, but inside out, if you will.

    Yeah, it's funny. The streamline version popped into my head while sitting
    on my porch watching the sunset and enjoying a cold one -- odd how your mind
    works.

    I realized that although cond can have the virtue of combining test
    condition and return, this problem still required an if to distinguish
    whether the start point was given -- it's more cumbersome to accomplish the
    same thing without the if.

    An interesting puzzle!
     
    Tom Smith, Apr 22, 2004
    #22
  3. David Kozina

    Tom Smith Guest

    If a utility function has too many 'bells and whistles' (perhaps in the
    form
    There's also a certain dead-weight factor. What are all these lines of code
    replacing? How many lines of generalized custom get-whatever code, with its
    own complicated calling syntax, are you dragging around in order to avoid
    how many lines of regular old built-in subrs? Once in a while Tony T sounds
    off on the subject of recoding built-in functionality. In extreme cases it
    can become an exercise in obfuscation, writing your own personal language
    that doesn't really do anything better, faster, or more succinctly than the
    language you began with.

    Maybe I'm lazy, but I don't have any "utilities" anywhere near the size and
    complexity of some these examples. I write small apps & just don't have the
    need. Once in a while I may define a get-whatever function locally within a
    lisp, if it avoids some repetitive code. But it doesn't go into the utility
    library unless it's been needed repeatedly.

    For instance, in one lisp (which actually defined a group of closely related
    commands) there were a dozen or so cases where I needed to prompt for a
    point, with or without the first-point, and with or without an osnap
    setting, so I wrote the following:

    (defun getpt (pt1 msg osnap / oos pt)
    (setq oos (getvar "osmode"))
    (if osnap
    (setvar "osmode" osnap))
    (setq pt
    (if pt1
    (getpoint (trans pt1 0 1) msg)
    (getpoint msg)))
    (setvar "osmode" oos)
    (trans pt 1 0))

    Example: (getpt nil "\nFirst point (mid):" 2)

    In this particular lisp, it reduced the repetitive coding for getting
    points. But I haven't needed this again in the last year, so I've had no
    reason to elevate it to a "utility" function. In isolated cases I simply use
    a normal getpoint. Without the extra osnap feature, and trans for dealing
    with coordinate systems, this routine reduces to

    (if pt1
    (getpoint pt1 msg)
    (getpoint msg))

    Sound familiar? These three lines are perfectly clear; replacing them with a
    single line which calls a bells-and-whistles super-getpoint, which requires
    another argument or two, isn't enough of a savings IMHO to justify the
    effort. Partricularly when I'm going to have to go look up the docs on the
    super-getpoint to make sure I'm using it right. And if the super-getpoint
    function itself is any more than 3 lines, without adding significant
    functionality to what it replaces, it's a net loss.

    To each his own. For the things I do, I get by okay on the K.I.S.S.
    principle.
     
    Tom Smith, Apr 22, 2004
    #23
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.