Bookmark Topic Watch Topic
  • Mark post as helpful
  • send pies
  • Report post to moderator
The advice is simple -- fix all compiler errors before running the application. Wait a minute, is running programs that don't compile even possible? What kind of FAQ entry is this? To understand this advice better, have you seen this compiler error?

Integrated Development Environments (IDEs in short), such as Eclipse, have an interesting feature. They allow you to run programs that don't compile! Obviously, the program does compile, but instead of generating correct code, the IDE's compiler will generate code that simply throws an exception, reporting uncompilable code, at portions of code that the compiler could not decipher correctly.

So, to elaborate, don't use this feature. Always fix all compile time errors before attempting to run the application. Why? To understand this a bit better, let's look at a case with lots of compile errors.

Have you ever compile a program and got dozens of errors? Which one do you fix first? Well, the answer is to fix the first one and then recompile the program. Why? Simply, when a compiler hits an error condition, it has to make assumptions in order to continue to look for more errors. After all, it is at an error condition, where does the good code start again?

Unfortunately, it isn't always correct. As the compiler encounters more errors, it may make incorrect assumptions, and it may actually miss compile errors. It may also find compile errors that don't exist. This is why you should only fix the first error, and recompile. Only when you get more experienced, should you start fixing more than a few before recompiling.

In summary, when using the command line compiler, javac, work to fix the first few before recompiling. And when using an IDE, fix the first few that are marked in red in the editor (and work your way down the source code until they are all fixed). With IDEs, not only are errors flagged, but hovering over them, and clicking, will bring up a menu of suggestions for corrections.

So, what about the IDE. and the ability to run uncompilable code? Doesn't it work the same way? Yes, and no. Yes, it also have to make assumptions, but no, using this feature, it doesn't list the errors. Instead it generates code that reports the compile error, when it is hit during runtime.

Unfortunately, while this error is the first error encountered during the execution, it may not be the first error encountered by the compiler during compile time. This error may be any of the dozens of errors reported during a compilation, and if it is one of the later ones -- when the compiler is confused -- this error is useless.

So, don't run programs that don't compile. Fix all compiler errors first.

    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!