- How Computers Think
- Commands, Functions and Operations
- Variables
- Conditions
- Loops
- Achieving the Impossible
- Writing Bug-Free Code
- Summary
- Q&A
- Workshop
Achieving the Impossible
Commands, functions, operations, variables, conditions, and loops are the fundamentals of computer programming. The tough part is putting the program together.
Programming is problem solving. Your programs are just sets of instructions to solve a big problem. So the first step in programming is to define what problem you want to solve.
A good example in the real world is going to the market to get milk. The problem would be "I need to get milk." But is that a clear enough definition to allow you to solve the problem?
What sort of milk do you want? whole? two percent? skim? How much do you want? a gallon? a pint? a liter? Where do you want to go to get the milk? the nearby supermarket? the convenience store? the local organic food store?
A better defined problem might be "I need to go to the nearby supermarket to get a gallon of skim milk."
Now that you have defined the problem, you need to determine what you want to do to solve it. You probably want to get in the car, drive to the store, find the milk, take it to the check-out line, pay for it, take it back to the car, drive home, and get out of the car. Breaking it down to these steps makes it easier to see exactly what is needed.
Each of these steps, however, can be broken down even further. Getting in the car involves opening the door, climbing in, placing the key into the ignition, turning it, and so on.
You can go even further. Opening the car door involves reaching for the handle, pulling gently on the handle, and then pulling on the door to open it. If the car was locked, you may also have had to take out your key, place it in the lock, turn the key, and so on.
Did you realize that so much was involved with going to get some milk? These steps seem so minor and detailed that you just don't think about them normally, but you have to do them.
As a computer programmer, you need to include every minor step in your program so that the computer knows how to perform the entire task.
TIP
If it helps, think of Flash as an alien from another planet or a prehistoric man thawed from ice. You have to explain every step of everything you want him to do, and you can't assume that he knows anything.
For instance, suppose that you want to make a space invaders game, just like the classic arcade game. It seems like a pretty big order at first, so you break it into steps. You've got the invaders, the shields, and the player.
Focus on the player's ship first. It should be able to move left and right, and fire bullets.
Focus on the movement first. The left and right arrow keys make it move from side to side. The program also needs to check to make sure that the ship doesn't move past the edge of the screen.
Focus on the movement to the left first. You've got to detect when the user presses the left arrow key and then reposition the ship slightly to the left when he does.
This last focus doesn't seem nearly as big a problem as the original onebuilding a space invaders game. You can achieve this step easily if you just know a few basic keywords.
This is the secret to computer programming. You need to break the problem down into smaller and smaller problems until you can handle each one.
If you are ever having difficulty figuring out how to solve a problem, it is probably because you have not broken it down into small enough pieces. Programming is partly knowing how to break down a big problem into smaller ones, and partly having the patience to implement each and every small step.
TIP
I can't stress this point enough. It is the single most important piece of information in this book. You must break down programming problems into smaller and smaller steps until you can solve each problem. About 90 percent of the time that people ask me for advice on how to do something on the computer, their problem turns out to be that they aren't breaking down the problem into small enough pieces.