Note on Syntax Errors and Compilers

   


In the following chapters, you are going to use the C# compiler extensively and will most likely experience it reporting numerous syntax errors in the command console due to incorrectly constructed statements or typing mistakes.

Fortunately, syntax errors are slowly becoming easier to detect and remove due to improved compiler diagnostics and error messages. The days when the programmer had to spend several hours tracking one syntax error down are nearly gone.

To improve your syntax error elimination abilities, keep the following tips in mind:

  • Line numbers in compiler error messages are not always correct You experienced this problem first-hand in the Listing 2.1 example when the compiler reported position (2,1) instead of (1,13). Always look directly before and after the error position when you search for the mistake.

    Understanding the compiler will enable you to find errors in the future more efficiently. After you find the true error, analyze why the compiler reported the wrong position and learn from the experience.

  • Several compiler error messages can be caused by just one real error Most compilers do not stop at reporting just the single real error. One syntax error might change the meaning of other parts of the program and trick the compiler to burst over with error messages. Consequently, if you can find the error of just one of many compiler error messages, fix that particular error and recompile.

  • Compiler messages often need interpretation Compilers are very exact contraptions. They try to report exactly what is wrong with your source code. However, you have to read between the lines sometimes to understand what an error message really means.

  • Hide parts of the source code temporarily during compilation Troublesome errors can often be found and eliminated by dividing the code into sections and having the compiler check the source code with various parts removed.

    When the part containing the problem is removed, the compiler will be silent. You can then inspect the removed section more closely. Some parts of code are easily hidden for the compiler by turning them into comments with //, or /*, */ as described in Chapter 3, "A guided tour through C#: Part I".

The three best ways to learn to program are writing programs, writing programs, and writing more programs. Only through hands-on practice can you acquire the mind of a proficient programmer. In Chapter 3, you will get the opportunity to write and analyze more programs to familiarize yourself with C#.


   


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net