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

Spaghetti Programming

Оглавление

In the early days of programming, most programs were fairly short and simple. A typical program may just calculate a mathematical equation, which to a computer, is just a little more challenging than adding two numbers together.

To write such small, single-task programs, programmers would typically start typing commands in their favorite programming language with little planning, just to write a program quickly.

Unfortunately, many programs aren’t just written once and then used forever. If a program isn’t working exactly right, or if the program needs to do something new that the original programmer didn’t include, you must take an existing program and modify it.

Modifying an existing program sounds simple, but it’s not. First, you have to understand how the program works so you’ll know exactly how to modify that program. If you try modifying a program without understanding how it works, there’s a good chance you could wreck the program and keep it from working, much like ripping out cables from your car engine without knowing what you’re really doing.

After you understand how a program works, the second step involves writing new commands into the existing program. Now, here’s where the problem occurs. Take an existing program and modify it once. Now take that same program and modify it again. Now take that same program and modify it 20 more times, and what do you get? Most likely, you’ll have a mishmash collection of code that works but isn’t organized logically, as shown in Figure 2-1.


FIGURE 2-1: Constantly modifying a program eventually creates an unorganized mess.

Modifying a program several times by yourself may not be so bad because you probably remember what you changed and why. But what happens if seven other programmers modify the same program seven different times and then none of them is around to help you understand what changes they made? Yep, you’d wind up with a bigger mess than before.

With constant modifications, a small, simple program can grow into a convoluted monstrosity that may work, but nobody quite understands how or why. Because the program consists of so many changes scattered throughout the code, trying to figure out how the program even works can get harder with each new modification.

With a simple program, the computer follows each command from start to finish, so it’s easy to see how the program works. After a program gets modified multiple times, trying to follow the order of commands the computer follows can be like untangling spaghetti (hence, the term spaghetti programming).

As programs kept getting bigger and more complicated, computer scientists realized that just letting programmers rush out to write or modify a program wasn’t going to work anymore. That’s when computer scientists created the first programming techniques to help programmers write programs that would be easy to understand and modify later.

Beginning Programming All-in-One For Dummies

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