The importance of Pseudocode
Going through Jonathan Weinberger’s courses over at GameDevHQ, I started investing more time researching pseudocode. It has allowed me to think about a problem in a high level of detail when applying this technique.
I have to admit that I am not a pseudocode pro yet! But with time, It will become an intuitive technique at my disposal.
Let me try to remember and describe what “Pseudocode” is without trying to butcher its meaning.
Pseudocode is a way to use informal English and describe the process of how an algorithm, a method, a class, or a program will work.
Here’s an example of one of many ways of writing pseudocode.
With a pseudocode like this, any programmer can read this in plain English and program the algorithm in their preferred language of choice. There isn’t a restriction. I then fill in the code underneath each pseudocode comment. This will allow me to be able to easily review and design detailed code.
Like I said before, there are many ways of writing pseudocode, and one way is to support the idea of iterative refinement. Iterative refinement is the concept of breaking things down by adding functionality step by step. Here’s the idea behind the technique in three steps:
- Start with a high-level design (Plain old English)
- Refine the design to pseudocode.
- Then you convert the pseudocode to source code.
The order of refinements in small steps will also allow you to check your design and catch errors along the way.
Here is my attempt to convert the pseudocode into source code. Not exactly accurate since I made up the pseudocode for this post. But I hope you get the idea behind it.
Also, pseudocode minimizes the effort of commenting by adding them after the source code is placed. So in other words, the pseudocode statements become the comments. Although, if you like to keep your code clean like me, then I would delete all the pseudocode after the code has been implemented.
Instead, I would allow myself to self-document my code through identifiers and methods and eliminate or minimize the need for comments. My variables and methods will document themselves.
That is all I have for now! Thank you for your time. And if there is something that I can improve on, please don’t hesitate to comment or shoot me an email!