Top Ten Programming Errors

Top Ten Programming Errors

Top ten

1. Spaces in Names
Spaces in identifier and function names will cause an error, for example, trying to use the variable Bank Balance instead of BankBalance

2. Spelling Mistake(s)
This is very common with identifier names, e.g. BankBlance instead of BankBalance. Also note that the identifiers you declare must match the names you use in the program.

3. Unmatched Parenthesis
Every opening parenthesis in your program must have a matching closing parenthesis. It is useful when coding to add a comment to label opening parenthesis and closing parenthesis, for example { // begin and } // end.

4. Unmatched Symbols
This may happen when you are using quotes or brackets, for example, alert (‘Hello ) ; is missing a closing quote. This may occur when you are using multiple brackets. You should make sure that all of the opening symbols you use have a matching closing symbol.

5. Incorrect Comparison Operator
In some computer languages the comparison of two variables is carried out using a double equals (==) rather than the single equals (=). The single equals carries out an assignment statement, such as a calculation, for example, average = (num1 + num2 + num3) / 3 ; Sometimes programmers will accidentally use the single equals for comparison and this will not work.

6. Duplicate Identifiers
The main cause of this occurs when you do not work from a design with a data table and an algorithm. For example, you may define and declare a variable in your program as average and then write a function that you also call average. One way to avoid this problem is to make sure that you always use a verb noun combination when naming functions, for example, CalcAverage ().

7. Incorrect Use of Functions
The correct syntax of functions should be adhered to at all times, for example, Math.round(33.9) ; as opposed to Round.math(33.9) ; If you are in doubt about the syntax of a function then look it up before you use it.

8. Incorrect Data Type Used
Be careful with your data declarations. Do not use an Integer when you want to use a Real (floating point) number. In many cases for calculations you will need to using floating point numbers. However, for situations where you wish to keep a count then integers are best. Also make sure that you use either parseInt or parseFloat when you are accepting input using the prompt command.

9. Case Sensitivity
Some languages have no case sensitivity. Therefore, Average will be viewed as being exactly the same as average. However, in some computer languages case sensitivity is inbuilt and if you use Average in one place and average in another then these will be viewed as two completely different variables.

10. Undefined Variables
This arises when variables are not declared before they are used. It is a good idea to declare variables and initialise them in an area at the start of your program that is clearly commented and organised.

Next: Testing and Debugging Quiz