HTML
  Home arrow HTML arrow Page 2 - Combating Coding Errors
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
HTML

Combating Coding Errors
By: Steve Adcock
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2002-11-28

    Table of Contents:
  • Combating Coding Errors
  • The 4 types of Programming Errors
  • PHP Specific Error Messages and Reporting
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Combating Coding Errors - The 4 types of Programming Errors


    (Page 2 of 4 )

    Usually, errors on the Internet can be broken down into 4 categories. Let's take a look at each in stride and consider an example of each.

    1. Syntax errors
    These are mistypings or other errors in code that prevent the execution of a script. A syntax error is the only error type that prevents the script from any execution. Let's take a look at an example using PHP:

    $x = 1
    echo $x;


    The code above produces an error because every executable line within PHP must be terminated with a semicolon. The second line is correct, but the first line is not.

    Other syntax errors include unbalanced parenthesis within mathematical equations, mistyped language keywords and extra curly braces -- among many others. Many times, syntax errors are the easiest to diagnose because error messages display the problem and also the problem's location.

    2. Semantic errors
    Semantic errors involve technically correct code which has fundamental problems with the meaning of the code. Since compilers do often point to the error, semantic errors can be found and diagnosed in many cases without too much heartache. The following example:

    include("file.txt");

    ... would be a semantic error if file.txt did not exist, and therefore could not be included within the document. Please note that although, on the surface, semantic errors can closely resemble syntax errors, a script can be executed until the point of the semantic error, unlike scripts that include syntax errors. This is because semantic errors contain correct code, like in our example above. It just so happens that file.txt does not exist, but the compiler has no way of knowing until it reaches that specific line of code.

    3. Logic errors
    The most difficult to diagnose, logical errors contain syntactically and semantically correct code, but do not execute the way the programmer has intended. This is often what drives programmers up the wall, especially with large and complex Internet applications.

    Logic errors can be as simple as incorrect operator usage (+ instead of -, / instead of *). Logic errors can also be as complex as database record calls and elaborate SQL statements. A logic error in PHP might look something like this:

    $States = array ("Alabama", "Alaska", "Arizona",
    "Arkansas", "California");
    echo "The first record in the States array is " . $States[1];


    The 5 states listed in alphabetical order are saved to an array called States. The logic error comes in the 2nd statement, when we intend to output the first record in the array, or Alabama. Experienced programmers will pick this error up immediately, but for those without much knowledge in programming, it may seem cryptic. Simply put, array positions begin with 0, not 1. The 2nd statement will output Alaska, not Alabama like we intended to do. To fix this, we would simply modify the output to $States[0] instead of $States[1].

    Another logic error might be including the wrong file, adding wrong variables or simply forgetting to manipulate data. Compilers cannot find logic errors, as it has no knowledge of what the programmer intends to do. In the above snippet of PHP code, there is nothing wrong with outputting cell position 1 in the array, so the compiler did it without any problem. Therefore, logic errors can only be determined and remedied by the programmer.

    4. Environment errors
    Environment errors are often forgotten, but are very real within the Internet community. Environment errors are errors beyond the programmer's control, and can include anything from absent language components within ASP to register_globals being turned off within PHP. It can be said, however, that environment errors occur least often out of the aforementioned 3 error types.

    More HTML Articles
    More By Steve Adcock


     

    HTML ARTICLES

    - Using a 3D HTML Table as a Recordset
    - Building a 3D HTML Table
    - Maximizing and Restoring HTML Images: Layer ...
    - Completing Construction of a Database Form w...
    - Maximizing and Restoring Images in a Tabular...
    - Building the Recordset for an HTML Database ...
    - Laying Out a Database Form with HTML
    - Tabular Database Form Functions with HTML
    - Tabular Database Forms with HTML
    - Using the Find Functions for HTML Database F...
    - Sorting for Database Forms with HTML
    - Edit and Other Database Form Functions with ...
    - More Database Form Functions with HTML
    - Database Form Functions with HTML
    - Using the HTML Table Element as a Recordset






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT