Название: Beginning Programming All-in-One For Dummies
Автор: Wallace Wang
Издательство: John Wiley & Sons Limited
Жанр: Программы
isbn: 9781119884422
isbn:
Remember: Focus on understanding programming, and then worry about understanding a particular programming language. After you understand how programming works, you can adapt to the next popular programming language of tomorrow, whatever that may be.
Chapter 2
Different Methods for Writing Programs
IN THIS CHAPTER
Spaghetti programming without a plan
Planning ahead with structured programming
Making user interfaces with event-driven programming
Organizing a program with object-oriented programming
Using protocol-oriented programming
Using design patterns
The goal of computer science is to find the best ways to write a program. The reality of computer science is that nobody really knows what they’re doing, so they’re making up stuff as they go along and pretending there’s a scientific basis for everything they do. The fact that multimillion-dollar programming projects routinely fall behind schedule and sometimes never work at all pretty much shows that computer programming is still less a science than an art.
Despite these problems, computer scientists are always searching for ways to make programming easier, faster, and more reliable by constantly developing
Better tools
Better programming languages
Better techniques for writing programs
Just as a carpenter doesn’t build a house with rusty saws and a broken hammer, computer scientists are always developing better tools to help them write, fix, and create programs. One of the first improvements computer scientists made was in developing faster compilers. Instead of waiting overnight to see if a program worked, programmers could use a fast compiler that could show them the results in seconds. Other tool improvements included editors that would show programmers the specific line where an error occurred and special programs (known as debuggers) for making sure that every part of a program worked correctly.
Another way to improve programmer efficiency involves creating better programming languages. Assembly language was easier to write and modify than machine language, and high-level languages are easier to write and modify than assembly language.
Computer scientists are constantly inventing new programming languages or improving existing ones. These improvements or new languages typically offer some feature that existing languages don’t offer or solve certain types of problems that existing languages do poorly. For example, the C++ language improves upon the C language, whereas the Java language improves upon the C++ language.
Perhaps two of the biggest problems with programming involve writing a program from scratch and modifying an existing program. When you write a program from scratch, you want to write a working program quickly with as few problems as possible.
That’s why programming languages include so many built-in commands. The idea is that the more built-in commands available, the fewer commands you’ll need to use to write a program and the shorter and easier your program will be to write in the first place.
In addition, many programming languages include built-in error-checking features to keep you from writing a program that doesn’t work. With some languages, it’s possible to write commands that work perfectly but can also crash the computer if you give those commands the wrong type of data.
In Book 1, Chapter 3, you find out more about the features of different programming languages.
More than half the battle of programming is writing a program that works. The second half is modifying that program later. When you need to modify an existing program, you must first understand how that existing program works and then you need to modify it without messing up the existing program commands.
To help you understand how a program works, many programming languages let you divide a large program into separate parts. The theory is that if one part of a program isn’t working or needs to be modified, you can yank out part of the program, rewrite it, and then plug it back into the existing program, much like snapping LEGO building blocks together.
Finally, the best tools and the latest programming languages won’t help you unless you know how to use them correctly. That’s why computer scientists are constantly developing new programming techniques that work no matter what tools or language you use.
In Book 1, Chapter 4, you find out more about the different programming tools computer scientists have created to make programming easier, faster, and more reliable.
This chapter discusses programming techniques based on problems encountered by programmers working in the real world. Basically, computer scientists keep developing and refining programming techniques after they see what really works and what doesn’t.
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 СКАЧАТЬ