Lesson 2 Logic

So you have a handle on these variable things? But to be honest, at this stage it’s not like you can see their use. It’s like learning about a piston before knowing what an engine is. Pistons are essential to drive the engine but until you see them in context, they are little more than a curiosity.
 
Coding is essentially a set of instructions. Just like a cookbook or a furniture construction pamphlet. The difference is that coding is a lot more powerful. I mean like the difference between a happy meal toy jigsaw guide and a car maintenance manual. It comes back to the point about power.

Take, for example, a guide to make a cup of tea. It could broadly follow the lines of the diagram below.

Making a cup of tea, in a flow diagram

This is pretty straight forward and I think we can agree that most people could follow it. However, it highlights the very blasé way that we tend to think and assumptions we make when we talk about tasks. It endows the reader with too much assumed knowledge. Let’s presume that we are talking to a small child. Put aside the fact that anyone who let’s a small child handle boiling water has some parental issues. Imagine the questions a child might ask:

  • How do you fill a kettle?
  • How much water do I put in?
  • Where are the tea bags?
  • Where are the mugs?
  • Can you take me to the hospital?

This is a taster of what you could expect. With the exception of the last flippant addition, they’re all quite valid but an adult would probably know these. The whole tea making procedure could be made to fill twenty pages depending on the level of detail you felt it necessary to go down to.

To expand a bit further, I have broken down the “fill the kettle” step below.

Filling the kettle, in greater detail

Welcome to the world of the coder. The computer knows how to do a few fairly basic things. Using these basic operations, you can build up complex and involved routines. Even a house is made from simple bricks. It is when someone understands the simple tools at their disposal and how to build from them that they are a coder.

What are these basic tools? This is where it actually gets easier. There are only three. That’s it. Three simple types of coding construct to remember. The beauty is that when you think about it they are three basic things you do over and over again all day without giving a second thought. They are:

  • Executive, a doing line.
  • Conditional, a decision line.
  • Iterative, a do this until line.

Yes, I know. The terms aren’t exactly intuitive. This is why I have included these next sections to break it down.