3.1. What is Code?

Computers are dumb, understanding not an ounce of context or intended meaning. 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 consider the error and adjust accordingly. Instead, they come to a grinding halt.

So how do we give computers instructions in the first place? The answer is to create code, which is a set of instructions for a computer 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 the answers, and respond by changing what is on the screen.
  2. Interact with other systems. Through code, we can interact with resources that are outside of our program. For example, we can read data in 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 snippets. 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. When we write code, we often need to carry out one task under a specific set of circumstances, but another task if the circumstances differ. We can write code to decide which action to take.

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