15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

130<br />

Organizing a Program<br />

More versus fewer keywords<br />

Computer scientists are divided on whether it’s<br />

better <strong>for</strong> a <strong>programming</strong> language to offer a lot<br />

of keywords:<br />

By offering a lot of keywords, a <strong>programming</strong><br />

language can let programmers write<br />

fewer keywords that do more work.<br />

By offering fewer keywords, a <strong>programming</strong><br />

language makes programmers write<br />

a lot of simple keywords just to do something<br />

that another language might be able<br />

to do with one keyword.<br />

Given these choices, having a lot of keywords<br />

in a <strong>programming</strong> language seems to make<br />

more sense. The problem is that the more keywords<br />

used, the harder it is to write a compiler<br />

<strong>for</strong> that <strong>programming</strong> language. The harder it is<br />

to write a compiler, the less efficient that compiler<br />

is in converting source code into machine<br />

language, just as it’s much harder to translate a<br />

Russian scientific paper into English than it is to<br />

translate a Russian children’s story into English.<br />

That’s one problem with the Ada <strong>programming</strong><br />

language. Ada uses lots of keywords, which<br />

makes <strong>programming</strong> easier but creating compilers<br />

<strong>for</strong> Ada much harder. This is one of the<br />

reasons why Ada compilers are much less<br />

widespread than compilers <strong>for</strong> the C <strong>programming</strong><br />

language.<br />

Unlike Ada, C offers a bare minimum of keywords.<br />

This makes <strong>programming</strong> in C harder<br />

because you need to write a lot of keywords to<br />

do something as seemingly simple as storing a<br />

text string. However, C’s handful of keywords<br />

makes it much easier to write a C compiler.<br />

To compensate <strong>for</strong> the lack of keywords, most<br />

C compilers include libraries of commonly used<br />

subprograms that can make C <strong>programming</strong><br />

easier and more useful.<br />

As a result, you can find C compilers <strong>for</strong> practically<br />

every computer because it’s much easier<br />

to write a C compiler than it is to write an Ada<br />

compiler. The more C compilers available, the<br />

easier it is to transfer (port) a C program to<br />

another computer. The C <strong>programming</strong> language<br />

is popular partly because you can run C<br />

programs on almost every computer.<br />

With a lot of keywords, Ada makes <strong>programming</strong><br />

easier <strong>for</strong> humans but harder <strong>for</strong> computers.<br />

In contrast, a handful of keywords in C<br />

makes <strong>programming</strong> harder <strong>for</strong> humans but<br />

much easier <strong>for</strong> computers. Given a choice<br />

between Ada or C, more people choose C, so<br />

having a <strong>programming</strong> language with fewer<br />

keywords seems to be more efficient (at least<br />

<strong>for</strong> the computer).<br />

Organizing a Program<br />

Every program consists of one or more commands, but there are different<br />

types of commands. Some commands tell the computer how to manipulate<br />

data, such as adding two numbers together. Other commands might tell the<br />

computer how to print data, display it on-screen, or save it on a disk.<br />

Although you could jumble all your commands together and still have a<br />

working program (see Book 1, Chapter 2 <strong>for</strong> more on programs), make your<br />

program easier to read and modify by organizing similar commands in different<br />

parts of your program.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!