Easy LISP Questions

Discussion in 'AutoCAD' started by ChrisW, Apr 12, 2004.

  1. ChrisW

    ChrisW Guest

    I was wondering is it better to have one file contain a lot of functions
    required for a project or have a separate file for each function? Is there
    a standard for variable naming, commenting, etc. I should follow? Thanks
     
    ChrisW, Apr 12, 2004
    #1
  2. ChrisW

    Paul Turvill Guest

    Whatever works for you. There's no particular standard that I know of, but
    if you plan to share any of your code with others, it's a very good idea to
    include comments detailing the app's use, required inputs (if any), and so
    on. Good (and, unfortunately, bad) examples abound; just find a style that
    makes you comfortable and stick with it.
    ___
     
    Paul Turvill, Apr 12, 2004
    #2
  3. ChrisW

    ChrisW Guest

    Thanks i will look for some examples

     
    ChrisW, Apr 12, 2004
    #3
  4. Hi Chris.

    The answer, as it is all too often, is: It depends.

    If the functions are only useful to the application then, by all means,
    place them in the application's file. However, if they are useful for other
    applications, you will find that you usually want those in separate files,
    or several related functions together in separate files.

    There is no "standard" for variable naming, aside from avoiding the use of
    protected symbols. However, do yourself a favor and name them clearly. This
    is desirable from a code maintenance perspective. Two years from now you
    don't want to try to figure out what variable 'a13' is used for.

    Your code, when using clear variable names and straightforward techniques,
    should be self-documenting to an extent. Comment where you think it is wise
    to further clarify or describe the program flow.


    --
    R. Robert Bell


    I was wondering is it better to have one file contain a lot of functions
    required for a project or have a separate file for each function? Is there
    a standard for variable naming, commenting, etc. I should follow? Thanks
     
    R. Robert Bell, Apr 12, 2004
    #4
  5. ChrisW

    BillZ Guest

    I think that (IMHO) that the more you can modulize your lisp the better. Being able to call the same subroutine from many different programs is a plus and makes updating things a lot easier.
    As far as variables: Give them names that visually give information about what the variable is for like "line_length1" or "circle_center1". Several months after you finish a program and have to go back and change or debug, you'll be glad you did.

    Bill
     
    BillZ, Apr 12, 2004
    #5
  6. ChrisW

    Tom Smith Guest

    I agree with the other comments.

    One suggestion: do an internet search on the phrase "lisp programming style"
    and study these very carefully. They will mostly be about Common Lisp -- the
    great grandparent of AutoLISP -- and have nothing at all to do with AutoCAD.
    This is fine. IMHO, too many of the Acad-based tutorials are based around
    hammering Acad into submission in a BASIC-like procedural fashion, as
    opposed to using lisp in a functional way that is more natural to the
    language. The best of the coders here really "get" lisp for what it is. Many
    casual lisp hackers don't get it at all.

    Giving variables meaningful names is very important, for the reasons stated.
    It's not a trivial exercise. Never use "a1" or "b2" -- use "beamlength" or
    "defaultdistance." It goes a long way toward making code readable and
    maintainable.

    Always declare variables local to your function.
     
    Tom Smith, Apr 12, 2004
    #6
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.