What is pseudocode?

Pseudocode spelt out in wooden blocks in front of code text

Pseudocode is a technique in computer science that is used to describe the various stages of an algorithm in a way that is easily understood by a human. Pseudocode typically follows the structures of a programming language, but presents the information in a way that is significantly easier to follow for a person unfamiliar with the code.

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?

Two people looking at code on a computer monitor

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.

RELATED RESOURCE

The data-driven enterprise

How organisations can truly make the most of their data

FREE 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' sequence alongside how it's written in Python.

Python:

n = int (input ("input message"))

for num in range (1, n+1): 

               if num % 3 == 0 and num % 5 == 0:

                       print ("FizzBuzz")  

              elif num % 3 == 0:

                       print ("Fizz")  

              elif num % 5 == 0:

                       print ("Buzz")  

              else:

                       print(num)

Possible pseudocode for the solution:

  • Start
  • Take 'num' as input from the user
  • Initialize num as 1
  • Run loop num till N+1
  • If num % 3 == 0 and num % 5 == 0 then print "FizzBuzz"
  • Elif num % 3 == 0 then print "Fizz"
  • Elif num % 5 == 0 then print "Buzz"
  • Else print num
  • End

In all cases, 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.

Bobby Hellard

Bobby Hellard is ITPro's Reviews Editor and has worked on CloudPro and ChannelPro since 2018. In his time at ITPro, Bobby has covered stories for all the major technology companies, such as Apple, Microsoft, Amazon and Facebook, and regularly attends industry-leading events such as AWS Re:Invent and Google Cloud Next.

Bobby mainly covers hardware reviews, but you will also recognize him as the face of many of our video reviews of laptops and smartphones.