Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud.
We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
"...If Debugging is the art of taking bugs out of programs, Programming must be the art of putting them in_"
Regardless of your planning or level of experience, script errors ("bugs") may initially prevent your server-side scripts from working correctly. This means that debugging, or the process of finding and correcting scripting errors, is crucial for the development of successful and robust CFML applications and JavaScript scripts.
While most of you might say, " Well, I already know all that; this is obvious," knowing the rules and following them are two different things. If anything, this article is meant to summarize basic debugging techniques to help you when it's two hours before that deadline and the program just doesn't work.
Common Errors
Program errors fall into three categories:
Syntax Errors
Run-Time Errors
Logical Errors
Syntax Errors A syntax error is a commonly encountered error that results from mistyped code or incorrect use of the script. For example, a misspelled command or an incorrect number of arguments passed to a function may generate a syntax error.
Example 1. Syntax error - Misspelling a CF function
<CFSET myVar ="hello world">
<CFSET X= urlendcodedformat(myVar)>
The following error message will pop up:
Error Occurred While Processing Request Error Diagnostic Information
There is no ColdFusion function named urlendcodedformat. Check the spelling of the function name in the ColdFusion documentation
The error occurred while evaluating the expression:
X= urlendcodedformat(myVar)
The error occurred while processing an element with a general identifier of (CFSET), occupying document position
The error in this case is a simple spelling mistake of the ColdFusion function Urlencodedformat(). Notice the extra "d": "endcoded" instead of "encoded."
Example 2. Syntax error - Missing attribute of a CF tag
<CFLOOP LIST="1,2,4,7,8"> </CFLOOP>
The following error message will pop up:
Error Occurred While Processing Request Error Diagnostic Information
Attribute set validation error in tag CFLOOP
The tag has an invalid attribute combination: the most likely attribute combination is
In this case the JavaScript function alert() was spelled correctly. However, JavaScript is case-sensitive and thus you will get an error message.
Note that in Netscape 4.x you don't see JavaScript errors unless you open up the JavaScript console by typing "javascript:" in the location bar.
Most syntax errors can be found by simply looking at the CF / JS error message. But in case that fails, try one of the following methods:
Use CF Studio's built in syntax checker (CF Studio à Options à Settings à Validation ).
Note that unlike ColdFusion, JavaScript is case-sensitive.
Have someone else look at the code; it usually helps.
Run-Time Errors Run-time errors occur after your script commences execution and result from scripting instructions that attempt to perform impossible actions. The following script tries to get the average salary of all the employees that make under $1,000,000.
Example 4. Run-Time error - CFML
<CFQUERY NAME="GETHIGHSALARY"
DATASOURCE="EMPLOYEES">
SELECT SUM(SALARY) AS TOTAL_SALARY ,
COUNT(EMPLOYEE_NUM)
AS EMPLOYEE_COUNT
FROM EMPLOYEES
WHERE SALARY < 1000000
</CFQUERY>
<CFSET AVG_HIGHSALARY =
GETHIGHSALARY. TOTAL_SALARY / GETHIGHSALARY.
EMPLOYEE_COUNT >
Let's presume that no one in the company makes under $1,000,000 a year, which in our case would create a division by zero (an illegal mathematical operation) and generate a run-time error (with the following error message):
Error Occurred While Processing Request Error Diagnostic Information
Division by zero is not allowed
The error occurred while evaluating the expression:
In this case the JavaScript loop tries to increment the variable j. However, since j is not set yet, the loop returns a JavaScipt error.
Most run-time errors can be avoided by exploring the following possibilities:
Use <CFPARAM> to ensure that your variables always have a default value, and that they always exist.
Take note when a variable can be null or zero; always be wary when division is involved.
Logical Errors A logical error can be the most insidious and difficult bug to detect. With logical errors, which arise from typing mistakes or flaws in programmatic logic, your script runs successfully, but yields incorrect results. For example, a CFML script intended to sort a list of values may return inaccurate results if the script contains LT instead of GT. The problem detecting logical errors is that usually no error message will appear. Your only clue to the existence of logic errors is the production of incorrect results.
In this case we have a list of names and we are trying to determine whether the name "shlomy" exists within that list. However, the variable DoesShlomyExist will return 0 because the CF function listfind is case-sensitive. The result will not be what we expected because we used the wrong function. (We should have used ListFindNoCase(), which is not case-sensitive.)
Example 6. Logical error - JavaScript
<script language="javascript">
for(x=2;x>1;x++)
{
// do something
}
</script>
In this case we created a javascript loop that starts with 2 and increments by one. However, the condition for ending the loop is that x will be bigger than 1 ( which is always true ). Thus, we get an endless loop that will consume all of the client's cpu & memory time and will only end when the client closes the browser.
Most logical coding errors can be avoided by sketching out your application before
you actually start coding. Here are a couple of other tips for you:
Output your variables: Sometimes you think a variable has one value but realize it had the exact opposite value two hours and 10 cups of coffee later. If you're encountering unexpected results and your code includes variables, use <cfoutput> to output the variable results at appropriate intervals, or use BreakPoints in thebuilt-in Debugging tool in CF Studio 4.0.
Create variables that print out at different parts of your code in order to establish which piece of code is running. This is very useful when you have a lot of nested <cfif> tags.
Fixing a Bug
Before you Start : Back up your program!
Sometimes while trying to fix a bug you change a great deal of the code and then find out that the error was actually in another section. By that time, you have already changed so much of the code that even ctrl-z won't save you now. When you experiment, it is far too easy to accidentally overwrite or delete necessary sections of code.
Fix one bug at a time.
If you know about several bugs, fix each one and test your fix before you move on to the next bug. Fixing a lot of bugs all at once without checking your work is just an invitation for more bugs to occur.
Do not patch, fix!
Sometimes you know a bug exists, but you don't really know why. Let's say you have a variable that is always one number less than you think it should be. You either sit there for a while and figure out why it's coming up short, or you can add one to the variable before using it, and move on. The latter method is called voodoo programming or patching. When you start thinking, "What the hell - why is index two instead of three? Well ... I'll just make it work for now and fix it later," you're slapping a band-aid on a potentially serious wound.
Voodoo programming may work in the short term, but you're looking at long-term doom. If you don't understand your code enough to really get rid of a bug, that bug will come back to haunt you. It will either return in the form of yet another weird error that you can't figure out, or it will make your code extremely hard to understand for the next poor soul cursed to look at it.
Look for similar bugs.
In some ways, the ability to cut and paste code is the worst thing for programmers. Often, you'll write some JavaScript in one function and then cut and paste it into another function. And if the first function had a problem, you now have problems in two functions. Use custom tags, use stored procedures, and modularize your code. It's faster in the long run.
If all else fails ...
If you're sitting there, staring at a bug, and you just can't figure it out, the best thing to do is walk away from your computer, take a stroll around the office, get a beverage - do something else.
And if that doesn't work ... Ask someone for help. You'll be amazed at how quickly a separate set of eyes will spot a problem.
About Shlomy Gantz Shlomy Gantz is the founder and president of BlueBrick, Inc., a technology management consulting firm based in New York. He has over a decade of application development experience, an extensive background in interaction design and project management, and has been building web-based solutions since 1996. Prior to founding BlueBrick, Shlomy was a senior consultant for Computer Horizons, leading large-scale projects for the airline industry. Prior to that he was co-founder and vice president of technology for CoreActive ACG., a New York–based consulting group and a premier Allaire partner.
Reader Feedback: Page 1 of 1
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice: