Pseudocode – Definition and Uses

pseudocodeterminology

I've seen a lot of mentions of Pseudocode lately, on this site and others. But I don't get it:

  • What is Pseudocode? For example, the Wikipedia article below says "It uses the structural conventions of a programming language, but is intended for human reading rather than machine reading." Does this mean that it isn't actually used to make programs?

  • Why is it used?

  • How is it used?
  • Is it considered a Programming Language? (See the above Wikipedia quote)
  • Is it commonly known/used?

I honestly don't know where to start with this. I have Googled it and I've seen the Wikipedia article on the topic, but I still don't fully understand what it is.

Best Answer

Pseudocode is, as the name implies, not real code, but it looks like code. It helps people to understand a problem domain or solution better without having to add all the baggage necessary when using a real language.

In short: it's used only for illustrational purposes.

Pseudocode and programming
There is no definition or fixed rule of pseudocode, it can be different each time. It is not a (real) programming language and no-one will consider it one. It cannot be compiled or used as a real programming language: if you could do that, it ceases to be pseudocode. Pseudocode does not need to be deterministic (a necessity for computers to compile), it rather needs to be understood by humans. To use pseudocode, you'll have to convert it to your favorite programming language. This conversion process can be different each time and no rules can be given for it because, again, pseudocode is like free speech: it can take any form.

Usages
It is commonly used, especially in the design phase of projects to help understand a certain approach to a problem. It's also commonly used in algorithm design, or when teachers draw something on the board. In all these cases it is not necessary to compile the code, you just want to understand the problem/solution.

Types of pseudocode
Pseudocode can be, but doesn't have to be of a certain type, i.e., you can have a stack-based pseudocode to illustrate MSIL, you can have an imperative pseudocode to illustrate Java, C#, C++, Python, you can have a functional pseudocode to illustrate F#, Haskell, SQL etc.

Examples
From the top of my head, but anything goes, because pseudocode can be invented on the spot:

XML pseudocode, showing a head+body structure that allows for multiple p-elements:

<head ...
   <title ...
</
<body ...>
   (<p>...)+
</

Imperative pseudocode, showing the diamond problem in languages that support multiple inheritance:

class A() { readFile(); }
class B() : A {}       // overrides readFile in A
class C() : A {}       // overrides readFile in A
class D() : B, C {}    // what definition of readFile should be used?

The above two examples obviously resemble some (type of) language, but aren't really that language and cannot possibly compile. They rather illustrate something that you want to explain.