Beginning Programming All-in-One For Dummies. Wallace Wang

Чтение книги онлайн.

Читать онлайн книгу Beginning Programming All-in-One For Dummies - Wallace Wang страница 38

Beginning Programming All-in-One For Dummies - Wallace Wang

Скачать книгу

target="_blank" rel="nofollow" href="#fb3_img_img_6058f3c1-813a-5825-9321-59c771c6a92f.png" alt="Remember"/> The technical features of a compiler are meaningless if

       The compiler stops being developed and supported.

       The compiler can’t run under the operating system or processor you need in the future.

       A particular technical feature is something you don’t need or care about.

      Supported language standards

      No two compilers are alike, even those that compile the same programming language, such as C++. The problem is that every programming language has an official “standard,” but the standard for most programming languages is usually far behind what people in the real world are actually using. (By the time an official standards committee agrees on the features of a given programming language, programmers have already created new features that eventually become standards in future versions of that language.)

      As a result, most compilers support a given language standard plus additional features that programmers have developed. Therefore, every compiler actually works with a different dialect of a programming language. So, C++ programs that run under the Microsoft Visual Studio compiler may or may not run the same when compiled under the GCC compiler, even though both compilers claim to support the “standard” C++ programming language.

      

Language standards are nice but generally useless when comparing compilers. What’s more important is whether a particular compiler offers the specific features you need or want, regardless of whatever particular standard it may follow.

      Code generation and optimization

      Every compiler converts source code into machine language, but some compilers can translate source code into more efficient machine language commands than other compilers. As a result, it’s possible to compile the same C++ program under two different C++ compilers and create identically working programs that consist of different machine language instructions.

      The goal of every compiler is to create a program that takes up as little memory and disk space as possible while running as fast as possible. Usually, compilers make a trade-off. To make a program run faster, the executable file may take up a large amount of disk space or require a lot of memory. If the compiler can reduce the size of your program and the amount of memory it needs to run, it may create a slow program.

Snapshot shows compiler optimization settings let you make your program as small and as fast as possible.

      FIGURE 4-1: Compiler optimization settings let you make your program as small and as fast as possible.

       How quickly the compiler works in translating your source code to machine code: In the old days, compilers could take hours or days to compile a simple program. Nowadays, compilers often work in minutes or even seconds. Shove in a program that consists of 800,000 lines of code, and in less than a minute, the compiler can create an executable file for you. The faster the compiler works, the less time you waste waiting to run and test your program.

       The performance of the machine language code that the compiler creates: Given the same program, one compiler may create a program that runs quickly, whereas a second compiler may create that same program that runs much slower.

      

Ideally, you want a compiler that both compiles fast and creates programs that run fast.

      Target platforms

      Most compilers can compile programs only for a specific operating system, such as Linux or Windows. However, what happens if you need to write a program that runs on two or more operating systems?

Snapshot shows a cross-compiler lets you write a program and compile it for multiple operating systems at the click of a mouse.

      FIGURE 4-2: A cross-compiler lets you write a program and compile it for multiple operating systems at the click of a mouse.

      With a cross-compiler, you can write a program once and compile it to run on multiple operating systems, effectively doubling or tripling your potential market. Without a cross-compiler, you may need to write a program for each compiler, under a different operating system, essentially doubling or tripling your work.

      

Although the idea of writing a program once and having it run on multiple operating systems may seem appealing, cross-compilers aren’t perfect. Chances are, you’ll have to tweak your program to run under each operating system, but those minor tweaks will be much easier than rewriting huge chunks of your program if you had to use two separate compilers.

      Cost

      Paying for a compiler doesn’t necessarily mean you’re getting a better compiler. The GCC compiler is free and one of the best compilers available.

      

Generally, you should only pay for a compiler if it offers a unique feature or programming language that you need or want to use. For learning purposes, you can find plenty of free compilers so you can study different programming languages without spending any money at all.

      Windows users will most likely want to consider Microsoft Visual Studio (https://visualstudio.microsoft.com), which comes in both free and commercial versions. Microsoft also offers a version of Visual Studio for the Mac to create macOS and iOS apps.

      To create Mac, iPhone, iPad, Apple Watch, or Apple TV apps, use Apple’s

Скачать книгу