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.

Spaghetti Programming without a Plan 31<br />

The rest of this chapter discusses <strong>programming</strong> techniques based on problems<br />

encountered by programmers working in the real world. Basically, computer<br />

scientists keep developing and refining <strong>programming</strong> techniques after they see<br />

what really works and what doesn’t.<br />

Spaghetti Programming without a Plan<br />

In the early days of <strong>programming</strong>, most programs were fairly short and<br />

simple. A typical program might just calculate a mathematical equation,<br />

which to a computer, is just a little more challenging than adding two numbers<br />

together.<br />

Book I<br />

Chapter 2<br />

Different Methods<br />

<strong>for</strong> Writing<br />

Programs<br />

To write such small, single-task programs, programmers would typically<br />

start typing commands in their favorite <strong>programming</strong> language with little<br />

planning, just to write a program quickly.<br />

Un<strong>for</strong>tunately, many programs aren’t just written once and then used <strong>for</strong>ever.<br />

If a program isn’t working exactly right, or if the program needs to do<br />

something new that the original programmer didn’t include, you must take<br />

an existing program and modify it.<br />

Modifying an existing program sounds simple, but it’s not. First, you must<br />

understand how the program works so you’ll know exactly how to modify<br />

that program. If you try modifying a program without understanding how it<br />

works, there’s a good chance you could wreck the program and keep it from<br />

working, much like ripping out cables from your car engine without knowing<br />

what you’re really doing.<br />

After you understand how a program works, the second step involves writing<br />

new commands into the existing program. Now, here’s where the problem<br />

occurs. Take an existing program and modify it once. Now take that same program<br />

and modify it again. Now take that same program and modify it 20 more<br />

times, and what do you get? Most likely, you’ll have a mish-mash collection of<br />

code that works, but isn’t organized logically, as shown in Figure 2-1.<br />

Modifying a program several times by yourself might not be so bad because<br />

you probably remember what you changed and why. But what happens if<br />

seven other programmers modify the same program seven different times<br />

and then none of them are around to help you understand what changes<br />

they made? If you guessed you’ll wind up with a bigger mess than be<strong>for</strong>e,<br />

you’re right.

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

Saved successfully!

Ooh no, something went wrong!