Pseudo Code — Sometimes I talk to computers

Objective: a description of pseudo code and its usefulness

I you want a coherent, precise, scientific definition… here is Wikipedia. My purpose is to show how pseudo code could be useful, especially when you are a beginner.

So what is it? Basically is a sort of meta language, in which you write computer instructions, floating between a programming and human language. You may find it on the web, on programming textbooks or even on code, as comments. In any case, it is used to clearly explain the algorithm, even to readers not knowing the specific programming language.

Anyone can understand this, right?

An approach I found useful, both during work and study, is to break a problem into little parts. I learnt it while studying physics, applied it when I was a researcher… but I found it useful in many other fields, ranging from everyday life problems to coding problems.

So, basically, I have a task or a problem to solve (now let’s consider coding), little or big, it can always be decomposed into other minor tasks/problems. For example: I want to build a Super Mario-like platform game. Let’s decompose it:

  1. Build the platforms
  2. Build the player
  3. Build the enemies
  4. Build power ups and coins
  5. Etc.

Each of them can be decomposed, for example let’s talk about the player

  1. Movement control
  2. Jump control
  3. Death
  4. Interaction with collectables
  5. Interaction with enemies
  6. Etc.

Again we can decompose… Got the idea?

But why is this related to pseudocode? Well, while facing a coding problem (let’s call it challenge ok? It’s cooler) you can write this down and have a rough idea of what you need and what you need to do. Here is an example concerning the power ups.

It may also be more specific and closer to a programming language.

This example is still quite understandable (less than before) but closer to code, with comparisons, value assignments etc. It is also clearer the algorithm to give player invincibility. This was a hard one, let’s look at this.

This would be a simple algo to implement the player death-by-fall, which would happen if the y position (2D game) would become lower than a fixed threshold value. The player loses a life and if the amount goes below zero: game over baby!

Now that the pseudo code is done, we would start actual coding, implementing the instructions in a real programming language (C# for Unity development). Once it is done, tested and working, all those comments must go. Even if they appear nice, someway clean and of course clear, always try to code as if your code would be manipulated later by some other colleague. So remember:

Clear the code of every pseudo code comment and, if possible, of every other comment explaining your code.

Code is like a joke: if you have to explain it… maybe it’s not that good.

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams