Читать книгу Beginning Programming All-in-One For Dummies - Wallace Wang - Страница 60

The efficiency of C

Оглавление

A C compiler tends to create smaller, faster, more efficient programs than compilers for other programming languages. The reason is that the C language is much simpler and, thus, easier to translate into equivalent machine language commands.

What makes the C language simpler is its small number of commands or keywords. Keywords are special commands used in every programming language. The more keywords a programming language uses, the fewer commands you need to make the computer do something. The fewer keywords a programming language offers, the more commands you need to make the computer do something.

Think of keywords like words in a human language. The fewer words you know, the more limited your communication is. If a little kid only knows the word hot, they can only express themselves in a limited manner, such as describing something as “very hot,” “a little hot,” or “not so hot.” However, if the kid knows a lot of different words, they can express themselves much better. Rather than use two or more words to describe something as “very hot,” “a little hot,” or “not so hot,” a kid with a richer vocabulary could describe the same items as “scalding,” “warm,” or “cool.”

A programming language with a lot of keywords allows you to write a program with fewer commands. That’s great from the programmer’s point of view but inefficient from the computer’s point of view.

The more keywords used in a language, the more work the compiler needs to do to translate all these keywords into machine language. As a result, programs written in languages that use a lot of keywords tend to run much slower than programs written in C.

A C program compiles to smaller, more efficient machine language commands because instead of offering a large number of keywords, the C language offers just a handful of keywords. This makes it easy for a compiler to translate the limited number of keywords into machine language.

However, as a programmer, you need to use C’s limited number of keywords to create subprograms that mimic the built-in commands of other programming languages. Because this can be impractical, the C language often includes libraries of subprograms that mimic the built-in commands of other programming languages.

The bottom line is that C programs tend to run faster and more efficiently than equivalent programs written in other programming languages. So, if you need speed, efficiency, and access to the computer hardware, the C language is the most popular choice.

Beginning Programming All-in-One For Dummies

Подняться наверх