Skip to main content

What is pseudocode? [Resolved]

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.


Asked January 11, 2017
Posted Under: Programming
68 views
7 Answers

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.


Answered January 11, 2017
 
It might be worthwhile to add that pseudo-code can live on any level of abstraction: You could describe the specific workings of an algorithm in a way that is easily translatable to real non-pseudo code, or you could give a very high-level overview of some approach using very broadly defined "methods" or "objects". It's a wide spectrum. – Joachim Sauer Feb 22 '12 at 12:02
 CanDoerz  10 months ago

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?

It is exactly that, it's code written in a human friendly form. It cannot be used to make a working program.

Why was it made/is it used?

Because Pseudocode is quick to write and quick to read. As it doesn't have language specific parts its clearer to read. Its also language independent so anyone can read it (for that reason its used in a lot of text books)

Is it considered a Programming Language? See the above Wikipedia quote.

No. A programming language requires more than just structure. It requires formal semantics, which pseudocode lacks.

Is it commonly known/used?

Yes. Anyone above a junior level should know how to read/write pseudocode. Its essential for reading a lot of text books and planning code in a team.


Answered January 11, 2017

If you have read the wiki article, then most of your questions should be clear. I will try to answer them in a simpler way here. Take a look at these 2 examples:

Part 1 - Examples

Code # 1 - Customer Registration - An example of process steps:

  1. Customer goes to registeration screen
  2. Customer enters his/her details.
  3. If valid details entered save customer information in database
  4. Else show dialog box with error message 100.

Code # 2 - Validate Customer Name - An example of programming function

Function ValidateCustomerName(Name1)

If (Name1 is entered and Name2 is entered) then return 1

If (Name1 is not entered) 

   Send Error Message

   return 0

Endif

...

End Function

Part 2 - Now to your questions

What is Pseudocode?

It is a way to write steps of an algorithm or a process.

Why was it made/is it used?

It is used to show the process or algorithm steps without being dependent on a specific programming language or special notations.

Is it considered a Programming Language?

It is not compilable and this is because it has no specific syntax and hence it is not a programming language.

If so, is it as capable as, let's say, Python?

It can be made as capable as you want it to be. You can write statements like : If Age is Valid...

Is it commonly known/used?

Yes. It is helpful when thinking about algorithms and for business analysts to provide specifications.


Answered January 11, 2017
 
@Jae, I appreciate the editing. – NoChance Feb 22 '12 at 20:33
 CanDoerz  10 months ago

The best example of Pseudocode was when I shared an office with a FORTRAN programmer, while I was programming in Pascal. Anytime we helped each other we had to write it in Pseudocode.At the time I didn't know FORTRAN so there is no way for me me to get the syntax correct (especially all the indents required locations for specific marks). He never had to write with semicolons. On the whiteboard we wrote in a Pseudocode so that it could be understood, without getting bogged down on complex syntax rules.

The are no strict constructs for Pseudocode. If the writer knows a language that uses "{" after an if statement they put it on the board, if they know python they don't. The goal is to quickly sketch out the basic approach to the problem, not absolutely correct code.

Teachers can use it to give guidance to a student, without giving them the correct answer. Once you know more then one language Pseudocode should be natural to use while sketching out code fragments.


Answered January 11, 2017

Pseudocode is not a language, not a convention. Every textbook or paper would use its own version of the pseudocode. As with many other informal mathematical "languages", in the best case it would be informally described in the paper itself, in the worst case the authors would expect it to be "obvious" enough.


Answered January 11, 2017
 
@Abel, an abstract language is a formalism too (at least when used in a more or less scientific paper). – SK-logic Mar 22 '12 at 11:37
 CanDoerz  10 months ago
 
This thread is about pseudocode. Formalism has nothing to do with that. But my comment was "pun intended" ;). – Abel Mar 22 '12 at 11:35
 CanDoerz  10 months ago
 
@Abel, there is no such a thing as an "obvious" formalism. Even something as "obvious" as decimal arithmetics must be properly introduced. Otherwise confusion is unavoidable, unfortunately. I've never seen an unambiguous pseudocode without at least some formal introduction attached. – SK-logic Mar 22 '12 at 11:34
 CanDoerz  10 months ago
 
In the bestest case it is obvious enough to not require any formal or informal description ;). – Abel Mar 22 '12 at 10:35
 CanDoerz  10 months ago

What is Pseudo code?

Pseudo code is basically written instructions of what a program should do to complete an operation. The pseudo code is written in your speaking language. You simply write down the steps of an algorithm or procedure to make it easier for you or someone else to read it and convert it to a real programming language.

Why was it made/is it used?

It was made to help you specify the steps of a procedure, process or an algorithm without using a programming language. One possible alternative is to use flowcharts.

Is it considered a Programming Language?

No, it’s not a programming language, since there are no formal rules.

Is it commonly known/used?

Personally, I always try to use pseudo code when writing algorithms or complex procedures.


Answered January 11, 2017

My personal definition of pseudocode is "the stuff I write in plain English on a sheet of paper when designing code"

Before coding from a pseudocode "design", I will add my pseudocode as comments. Then working through those comments I can add the "actual" code which performs the task described.

There may be a formal name, which I am unaware of, for this method of coding, and I only use it when doing something new/complicated.


Answered January 11, 2017
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA