15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

134<br />

Dividing a Program into Subprograms<br />

Subprogram<br />

Figure 1-5:<br />

Storing subprograms<br />

in<br />

separate<br />

files can<br />

make it easy<br />

to read and<br />

modify one<br />

part of a<br />

large<br />

program<br />

without<br />

having to<br />

see any<br />

other part of<br />

that same<br />

program.<br />

Main program<br />

Math commands<br />

Math commands<br />

Saving commands<br />

Saving commands<br />

Printing commands<br />

Printing commands<br />

Printing commands<br />

The more commands you<br />

cram into a program, the<br />

larger the program gets.<br />

Main program<br />

Run math program<br />

Run saving program<br />

Run printing program<br />

By dividing a large<br />

program into smaller<br />

subprograms and storing<br />

those subprograms in<br />

separate files, you can<br />

dramatically shrink the size<br />

of your main program.<br />

Math commands<br />

Math commands<br />

Subprogram<br />

Saving commands<br />

Saving commands<br />

Subprogram<br />

Printing commands<br />

Printing commands<br />

Printing commands<br />

By storing subprograms in separate files, you can write a program with multiple<br />

<strong>programming</strong> languages. That way you can write your main program in<br />

BASIC and then write subprograms in C or Java. By doing this, you don’t<br />

have to limit yourself to the strengths and weaknesses of a single <strong>programming</strong><br />

language. Instead, you can take advantage of the strengths of each <strong>programming</strong><br />

language.<br />

If you’re writing a hard disk diagnostic program, you could write the whole<br />

thing in C because C is great <strong>for</strong> accessing the hardware of a computer.<br />

However, you may find that C is too clumsy <strong>for</strong> printing reports or displaying<br />

in<strong>for</strong>mation on-screen. In that case, what are your choices? You can<br />

✦ Use C to write the whole program. This is great <strong>for</strong> accessing computer<br />

hardware but hard <strong>for</strong> writing the rest of the program, like the user<br />

interface.<br />

✦ Use an easier language, like BASIC, to write the whole program. This<br />

is great <strong>for</strong> writing every part of the program except the part needed to<br />

access the computer hardware.<br />

✦ Use a mix of two or more <strong>programming</strong> languages. Use BASIC to write<br />

most of the program and then use C to write a subprogram to access the<br />

computer hardware.

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

Saved successfully!

Ooh no, something went wrong!