What is pseudocode?
We take a closer look at the descriptive take on programming languages
Whether you’re a professional developer, hobbyist, total novice, or just someone who has hit F12 in a web browser, we’ve all seen pages full of code. For the uninitiated, however, high-level languages complete with unique types, keywords, syntaxes and more, can be difficult to decipher.
Pseudocode aims to bridge the gap between code and plain English, allowing developers to explain more clearly to non-developers what a specific feature or algorithm achieves in an application.
The code written by developers is meant to be readable by machines, not humans. Machines are far better equipped to read endless parentheses, curly brackets, and pipes than we are; we're simply too used to the comparatively inefficient letters, words, and symbols. Pseudocode strikes a balance between the two, explaining complex computer science concepts to those who don’t have a deep understanding of programming.
Why is pseudocode code used?
Pseudocode keeps some aspects of the language intact in its representation; if you were explaining how to create a loop in pseudocode, you may still use the ‘for’ keyword but you may choose to omit ‘var’ and ‘let’ keywords to describe variables and constants. Common syntax seen in popular programming languages can also go out the window; instead of assigning values to properties with ‘=’, you may simply use an arrow to show which value belongs to which property in code.
Just in the same way we humans use our native languages differently to accommodate different audiences and purposes, writers of pseudocode can get creative with how they represent complex structures in a way that’s more familiar to other people. There is no strict style or syntax for pseudocode, it’s all about translating machine code for humans in the clearest way possible.
The data-driven enterprise
How organisations can truly make the most of their dataFree Download
This form of coding is often used to map out or pre-plan how a programme will work before then translating it into a real language. It's another way of planning, in that it could replace a series of flowcharts and unified modelling language charts that show how an algorithm or system works, as well as its key aims. This is especially useful for people who'd ideally want to ensure the core code is foolproof, and that whatever it is eventually translated into has a fixed point of reference in relatively plain English.
Pseudocode can also help to spot any potential flaws in the code before an app or algorithm is written out in full, which lends itself to a far more efficient process in the longer-term. When it comes to patching any errors in future, for example, the process could be much smoother.
Beyond the practical benefits of pseudocode, programmers often use pseudocode as a point of reference to translate a piece of code from one language to another, as it documents the underlying functions and aims of a programme; almost like a translatory aid. But it can also be helpful to add any additional functions, in terms of visualising where these may fit into the overall programme.
So where are you likely to see it? Pseudocode is often found in scientific publications or textbooks where it can be used to help outline specifically how certain algorithms can be deployed in certain tasks and use cases. Overall it's useful for straightening out how a function would work for any users who aren't necessarily versed in a particular language they're working with at any given time.
Examples of pseudocode
As we've already mentioned, it's important to remember that pseudocode can't be fed into a computer, and is therefore only designed for other people to read. Below we've included an example of how we can potentially use pseudocode to write the 'FizzBuzz Algorithm' alongside how it's written in Python.
num : 1
for num in range(1, 21):
Pseudocode can, however, be even more stripped back than the above example. Here's another example of pseudocode in action, again, versus its equivalent in Python.
Num : INTEGER
Num = int(input("Please enter a number: ))
for Number in range (1,11):
In all cases, however, programmers advise that you use proper naming conventions, that you use indentation and white spaces, and that you keep it simple and concise. You shouldn't, on the flip side, make it too abstract or too generalised.
Join the 90% of enterprises accelerating to the cloud
Business transformation through digital modernisationFree Download
Delivering on demand: Momentum builds toward flexible IT
A modern digital workplace strategyFree download
Modernise the workforce experience
Actionable insights and an optimised experience for both IT and end usersFree Download
The digital workplace roadmap
A leader's guide to strategy and successFree Download