3.1. What is Code?

Despite the sci-fi images of powerful, advanced machines, computers are actually dumb. They react mechanically to the instructions we give them, and they cannot deviate from the steps we tell them to follow.

If our instructions are even the slightest bit off, computers cannot ignore the error. As a result, they will return incorrect results, or they may just come to a grinding halt.

So how do we give computers their instructions? The answer is to create code, which is a set of steps for the computers to follow.

3.1.1. What Code Can Do

Here is a short list of SOME of the tasks we can carry out with code:

  1. Interact with users. Through code, we can ask a user questions, store their answers, and respond by changing what is on the screen.

  2. Interact with other systems. Through code, we can access information outside of our program. For example, we can read data from a file on our computer, or we can ask a server on the other side of the planet for information.

  3. Repeat tedious tasks. Have a few thousand emails to send? Need to spellcheck several thousand words? You can do these things with just a handful of code.

  4. Reuse useful code. Rather than copy/paste the same lines of code in multiple places, we can assign a name to that code. This allows us to use it wherever we like by simply referring to its name.

  5. Decide what to do based on the current situation. We can write code to decide which action to take based on data—like when the thermostat in our house should turn the heat on or off.

Of course, in order to work, code needs to follow a specific set of rules.