19

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.

Dynamic
  • 5,746
  • 9
  • 45
  • 73
  • 7
    Please provide specific quotes and questions from the Wikipedia article. All of your questions **are** answered there. If you can't understand the words or phrases, please quote a specific word or phrase in your question so we can explain it. It's difficult to know what you found confusing in that article. Rather than repeat that article here, it would help if you could reference the specific things that confused you. – S.Lott Feb 22 '12 at 10:58
  • @S.Lott: Finished – Dynamic Feb 22 '12 at 11:06
  • 20
    `while (you.doNotUnderstand(pseudocode)) { q = you.askQuestion(); a = we.answer(q); you.digestAnswer(a) }` – Joachim Sauer Feb 22 '12 at 11:22
  • 3
    `if (question.IsAnswered) then you.UnderstandPseudoCode <- true` – e-MEE Feb 22 '12 at 11:29
  • 1
    It is middle ground between natural language and programming language - it is more formal than spoken language, but less formal than a real programming language. – Ingo Feb 22 '12 at 14:43
  • [pseudo](https://www.google.com/webhp?sourceid=chrome-instant&ix=sea&ie=UTF-8&ion=1#hl=en&site=webhp&q=pseudo&tbs=dfn:1&tbo=u&sa=X&ei=VVBFT5btN-KSiQL89aTFDg&ved=0CCcQkQ4&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=573259cdfc6609cc&ix=sea&ion=1&biw=1214&bih=754)-code == false/sham/not geniune code –  Feb 22 '12 at 20:31

8 Answers8

19

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.

Abel
  • 912
  • 8
  • 13
  • 14
    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
8

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.

S.Lott
  • 45,264
  • 6
  • 90
  • 154
Tom Squires
  • 17,695
  • 11
  • 67
  • 88
6

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.

Dynamic
  • 5,746
  • 9
  • 45
  • 73
NoChance
  • 12,412
  • 1
  • 22
  • 39
4

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.

mhoran_psprep
  • 2,328
  • 2
  • 16
  • 14
2

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.

SK-logic
  • 8,497
  • 4
  • 25
  • 37
  • In the _bestest_ case it is obvious enough to not require any formal or informal description ;). – Abel Mar 22 '12 at 10:35
  • @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
  • 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
  • @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
2

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.

0

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.

AnthonyBlake
  • 285
  • 1
  • 7
-4

As how my programming lecturer said:

Pseudocode is the English version of any programming language.

CincauHangus
  • 105
  • 3
  • 2
    -1 Not helpful. The quote only makes sense among an explanation of pseudocode (missing in this answer). Otherwise, it could be quite misleading. A newbie could wonder: _well, C#'s methods are all in English, so that means the C# I'm using is Pseudocode, right...? What do they call it when they're using C# in Germany?_ – doppelgreener Mar 01 '12 at 00:49