Pseudocode — Your Best Friend When Programming
We are used to do complex things without ever thinking about the individual steps. Driving a car for example. It’s simple right — and once you have been driving a few years, you won’t even give it a thought. But well it’s not. Just watch a beginner trying to coordinate all those steps. Or drinking a coffee … that’s really simple isn’t it?
Well in truth it isn’t but we have an amazing capability to process complex steps automatically once we have learned them. However when we write a computer program we need to exactly understand the individual steps and write them in code. This can be extremely challenging especially when jumping right into coding.
Rather than starting right away with the code, we should be very clear about the steps we need.
In programming this is often done through pseudocode.
What is pseudocode
Pseudocode is a way of writing code without following a specific programming language or syntax. It remains closer to our own daily language. It is therefore easier to read as code and it is easier to recognize the missing pieces. Thus it helps to gain more clarity before coding the related steps in your programming language.
An example of pseudocode
Let’s say we want the player to die once he has no more live. Our pseudocode could look like this:
Player has 10 liveIf live is 1 or greater than the player can continueIf live is bellow 1 then destroy the player
Note: As you get more experienced, the language you are using in your pseudocode is likely to get closer to the actual coding categories. But for now this will do.
From the pseudocode we understand, we need to have something to store the live of the player, thus we create a variable:
private int _live = 10;
We also need an if statement to check if the live is bellow 1. We actually do not need to check for the positive value (>=1) as the game object, here the player, will continue to exist.
if (_live < 1){Destroy(this.gameObject);}
This was a very simple example. The more complex our problem becomes, the more valuable is a first write-up in pseudocode.
Image Monkey: Photo by Juan Rumimpunu on Unsplash