Название: Beginning Programming All-in-One For Dummies
Автор: Wallace Wang
Издательство: John Wiley & Sons Limited
Жанр: Программы
isbn: 9781119884422
isbn:
An editor and a compiler are absolutely necessary to write and distribute programs. However, most programmers also use a variety of other tools to make programming easier. To help them track down bugs (problems) in a program, programmers use a special tool called a debugger. To help them identify which parts of a program may be making the entire program run too slow, programmers can use another tool, called a profiler.
For distributing programs, programmers often use a help file creator and an installer program. The help file creator makes it easy for the programmer to create, organize, and display help that the user can read while using the program. The installer program makes it easy for users to copy all the necessary files on to their computer so the program runs correctly.
Finally, programmers may also use a special tool called a disassembler, which can pry open another program to reveal how it works. Disassemblers are often used by security professionals to analyze how viruses, worms, and spyware programs work. For less honorable uses, programmers can also use a disassembler to dissect a rival program and study how it works.
In many cases, programmers use an integrated development environment (IDE) that combines the features of an editor with a compiler and a debugger. That way, they can just use a single program to write, debug, and compile a program, instead of relying on two or more separate programs.
Programmers often get so attached to their favorite programming tools that they argue the merits of their favorite editor or compiler with all the passion of a religious fanatic. Just as there is no single programming language that’s the best language to use at all times, there is no single programming tool that’s the best tool to use all the time.
Choosing a Compiler
No two compilers work exactly the same, even compilers designed for the same language, such as two competing C++ compilers. It’s perfectly possible (and quite common) to write a program that works perfectly with one compiler but doesn’t run at all under another compiler without minor (or massive) changes.
When Microsoft wrote the Mac version of its Microsoft Office suite, it used CodeWarrior, which is a C++ compiler. Unfortunately, the CodeWarrior compiler ran only on the PowerPC processors, which were used in older Mac computers. When Apple switched to Intel processors, Microsoft had to dump the CodeWarrior compiler and use a different compiler called Xcode.
Because CodeWarrior and Xcode are both C++ compilers, Microsoft could theoretically compile the same C++ program under both CodeWarrior and Xcode with no problems. Realistically, Microsoft had to rewrite major portions of their C++ programs just to get them to run under the Xcode compiler. The moral of the story is that switching compilers is rarely an easy decision, so it’s important to choose the “right” compiler from the start.
At one time, the CodeWarrior compiler was considered the “right” compiler to use for creating Mac programs. What made CodeWarrior suddenly turn into the “wrong” compiler was when Apple switched from PowerPC processors to Intel processors. Everyone who had used the CodeWarrior compiler had to switch to the Xcode compiler. Bottom line: What may seem like the “right” compiler today could later turn out to be the “wrong” compiler through no fault of your own or the compiler company.When choosing a compiler, you have to consider your needs, the compiler company’s reputation, and the compiler’s technical features.
Defining your needs for a compiler
The most important choice for a compiler centers solely on what you need. Follow these steps:
1 Decide which programming language you want to use.If you want to write C++ programs, you need a C++ compiler. If you want to write C# programs, you need a C# compiler. Many compilers can work with multiple languages, such as C and C++.
2 Decide which operating system you want to use.If you want to write C++ programs for macOS, your choices immediately narrow to the small list of C++ compilers that run under macOS.
3 Choose a compiler that has the best chance of being around years from now.Most companies prefer using compilers from brand-name companies, like Apple or Microsoft. Even compilers from big-name companies are no guarantee against obsolescence. Microsoft has stopped supporting its compilers over the years, such as Microsoft Pascal and Visual Basic 6. If you used either of these compilers to write a program, you had to change compilers when Microsoft stopped developing them.Many people are choosing open-source compilers. Open source simply means that the source code to the compiler is available freely to anyone. Not only does this mean that open-source compilers are free (compared to the hundreds of dollars you can pay for a brand-name compiler), but it also guarantees that the compiler can’t become obsolete due to lack of support. If you use a compiler from a company that goes out of business, you’re forced to port (transfer) your program to another compiler, which means having to rewrite the program to run under a different compiler.
Because anyone can examine and modify the source code to an open-source compiler, anyone can make changes to the compiler to improve it. One of the most popular open-source compilers is GCC (https://gcc.gnu.org
), which stands for GNU Compiler Collection.
Originally, GCC only compiled C source code, but later versions of GCC compile several different languages, including Ada, C, C++, Java, and Objective-C, with more programming languages being supported every year. Even better, the GCC compiler also runs on a variety of operating systems, such as Linux and Windows, so if you write a program using the GCC compiler, you can recompile your program to run under another operating system with minimal changes (ideally).
The GCC compiler actually consists of two parts:
The front end of the compiler translates source code into an intermediate format:To write C++ programs, you must use the C++ front end of the GCC compiler.To write Ada programs, use the Ada front end of the GCC compiler.By creating front ends for different languages, programmers can make the GCC compiler compile more programming languages.
The back end of the compiler finishes translating the intermediate code into actual machine code.
Evaluating the technical features of a compiler
After you choose a particular programming language and pick which operating systems you want your programs to run on, your list of compiler choices is likely narrowed to one or two choices. Given two compilers that both meet your needs, you can pick the “best” compiler by examining their technical СКАЧАТЬ