#1
  1. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,242
    Rep Power
    967

    Asking for help and debugging tips


    First, let me remind people that when you post a question about a problem that you are having, post the error message. And if you are posting code, post the line number of the error.

    I've also noticed a trend where people paste hundreds of lines of code into a message and ask for help. Please do not do this. Myself and the others trying to answer questions do not have the time to read through all that code. Remove as much extraneous code as you possibly can from the script before you post it. In many cases, you'll find that by simplifying the code you will actually discover the problem for yourself. But even if you can't solve it yourself, posting specific code makes it much easier for us to help you. I'm probably going to start posting links to this message when future threads have large amounts of code pasted.

    Remember to use <cfdump> and <cfabort>, these are the best debugging tools that CF developers have! Have a problem with a form field on your action page? Place a <cfdump var="#form#"><cfabort> at the top of the page and confirm that the form scope has the variables and values that you are expecting. <cfdump> works with all ColdFusion data types, so you can dump query result sets, CFC instances, nested arrays of structures, XML document objects, Java objects, and anything else. Use this capability!

    Remember that problems with conditional logic are actually among the easiest problems to solve. Remove all the extra code until you are left with only the conditional logic and some text to help you test which condition is running. And remember if you are matching on strings in your conditional that extra spaces will cause otherwise identical strings not to match. Use the trim() function to get rid of extra spaces on either side of a string.

    If anyone has tips of their own, please post them to this thread. I'll make it a sticky. Thanks!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    24
    Rep Power
    0
    The one thing I would add is an expansion of the statement (slightly modified) "Remove as much extraneous code as you possibly. In many cases, you'll find that by simplifying the code you will actually discover the problem for yourself."

    <!--- ---> is your friend! I was programming CF for 6+ years before I learned about the CF comment (duhhh), which is different and more powerful than the html comment. Use this to block our entire sections of code until you get the page running without errors and then unblock a piece at a time until you find the offending section.

    Hope this helps...

IMN logo majestic logo threadwatch logo seochat tools logo