|
A computer's processor, such as variants of the x86 processor that is popular for small computers, only knows one language, its native machine language. Other programming languages need to be translated to machine language (or implemented in some other way).
A compiler is software that translates one programming language to another. We will use a compiler called g++ that translates from C++ to machine language.
Compilers do more than translate. They also report errors and warnings.
An error is a mistake that is so severe that the compiler cannot make sense of the program. When there is an error, no machine language program is produced, and we say that the program does not compile.
There are pitfalls that are easy to fall into, even for experts. A warning tells the programmer to look more carefully for a pitfall. It is a strong suggestion that needs to be fixed.
When there are warnings but no errors, the compiler will translate the program, so you can run it if you want to.
But experts do not ignore warnings. You should not either. Don't try the software without paying attention to warnings. That is usually a waste of time. Heed the compiler's advice.
Compilers try to be helpful. If you omit a right parenthesis, g++ will tell you so. If you use a variable frog at line 24 in program p1.cpp, but frog has not been declared, g++ will tell you that by saying
p1.cpp:24:16: error: 'frog' was not declared in this scopep1.cpp:24:16 means that the error occurs at character 16 of line 24 of p1.cpp.
You will find error messages suggestive of ways to fix the program. But watch out! A compiler is an excellent adviser but a terrible boss. The most obvious way to fix an error is often not the right way. For example, if you have not declared frog , and you are too tired to think, you will probably simply declare frog , since that seems to be what the compiler is telling you to do. But the real error might be that you have simply misspelled from.
You must be the boss. Always think about the right way to fix an error. Never let a compiler bully you into making a change that takes a program farther away from being correct. Never think that your task is to make the compiler shut up. Your task is to make the program work.
Remember this: The compiler does not know what you want your program to do. Following a compiler blindly will not lead you in the right direction.
Integrated development environments (IDEs) such as Microsoft Visual Studio, Eclipse and XCode are typically designed to offer help in writing software, and are especially useful for large pieces of software where they help a person to navigate the complexity and size of a project. IDEs are designed for experts, not for novices. Experts know that most of the suggestions that an IDE offers are are wrong, and they only use the suggestions that are on the right track.
Do not let an IDE be your guide. It does not know what you are trying to do, and, if allowed to, it will lead you in the wrong direction. If you are at all tempted to try its advice without thinking out whether that advice is correct, I strongly recommend that you either turn off the advice or stop using the IDE.
|