All Topics  
Pseudocode

 

   Email Print
   Bookmark   Link






 

Pseudocode



 
 
Pseudocode is a compact and informal high-level description of a computer programming
Computer programming

Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language....
 algorithm
Algorithm

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing....
 that uses the structural conventions of some programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
, but is intended for human reading rather than machine reading. Pseudo-code typically omits details that are not essential for human understanding of the algorithm, such as variable declarations, system-specific code and subroutines. The programming language is augmented with natural language
Natural language

In the philosophy of language, a natural language is a language that is spoken, Sign language, or writing by humans for general-purpose communication, as distinguished from formal languages and from constructed languages....
 descriptions of the details, where convenient, or with compact mathematical notation.






Discussion
Ask a question about 'Pseudocode'
Start a new discussion about 'Pseudocode'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Pseudocode is a compact and informal high-level description of a computer programming
Computer programming

Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language....
 algorithm
Algorithm

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing....
 that uses the structural conventions of some programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
, but is intended for human reading rather than machine reading. Pseudo-code typically omits details that are not essential for human understanding of the algorithm, such as variable declarations, system-specific code and subroutines. The programming language is augmented with natural language
Natural language

In the philosophy of language, a natural language is a language that is spoken, Sign language, or writing by humans for general-purpose communication, as distinguished from formal languages and from constructed languages....
 descriptions of the details, where convenient, or with compact mathematical notation. The purpose of using pseudocode is that it is easier for humans to understand than conventional programming language code, and that it is a compact and environment-independent description of the key principles of an algorithm. It is commonly used in textbooks and scientific publications that are documenting various algorithms, and also in planning of computer program development, for sketching out the structure of the program before the actual coding takes place.

No standard for pseudocode syntax exists, as a program in pseudocode is not an executable program. Pseudocode resembles, but should not be confused with, skeleton programs
Skeleton (computer science)

Skeleton programming is a style of computer programming based on simple high-level program structures and dummy code. Program skeletons resemble pseudocode, but allows parsing, compiler and testing of the code....
 including dummy code
Dummy code

In computer programming, dummy code is inserted in a Skeleton to simulate processing and avoid compiler error messages. It may involve empty subroutine declarations, or functions that return a correct result only for a simple test case where the expected response of the code is known....
, which can be compiled
Compiler

A compiler is a computer program that transforms source code written in a programming language into another computer language . The most common reason for wanting to transform source code is to create an executable program....
 without errors. Flowchart
Flowchart

A flowchart is common type of chart, that represents an algorithm or Process , showing the steps as boxes of various kinds, and their order by connecting these with arrows....
s can be thought of as a graphical alternative to pseudocode.

Application

Textbooks and scientific publications related to computer science
Computer science

Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems....
 and numerical computation often use pseudocode in description of algorithms, so that all programmers can understand them, even if they do not all know the same programming languages. In textbooks, there is usually an accompanying introduction explaining the particular conventions in use. The level of detail of such languages may in some cases approach that of formalized general-purpose languages — for example, Knuth
Donald Knuth

Donald Ervin Knuth is a renowned computer science and Emeritus of the Art of Computer Programming at Stanford University.Author of the seminal multi-volume work The Art of Computer Programming , Knuth has been called the "father" of the run-time analysis, contributing to the development of, and systematizing formal mathematical techn...
's seminal textbook The Art of Computer Programming
The Art of Computer Programming

The Art of Computer Programming is a comprehensive monograph written by Donald Knuth that covers many kinds of programming algorithms and their analysis....
 describes algorithms in a fully-specified assembly language
Assembly language

An assembly language is a low-level language for programming computers. It implements a symbolic representation of the numeric machine codes and other constants needed to program a particular CPU architecture....
 for a non-existent microprocessor
Microprocessor

A microprocessor incorporates most or all of the functions of a central processing unit on a single integrated circuit . The first microprocessors emerged in the early 1970s and were used for electronic calculators, using Binary-coded decimal arithmetic on 4-bit Word ....
.

A programmer
Programmer

A programmer is someone who writes computer software. The term computer programmer can refer to a specialist in one area of computer programming or to a generalist who writes code for many kinds of software....
 who needs to implement a specific algorithm, especially an unfamiliar one, will often start with a pseudocode description, and then simply "translate" that description into the target programming language and modify it to interact correctly with the rest of the program. Programmers may also start a project by sketching out the code in pseudocode on paper before writing it in its actual language, as a top-down structuring approach.

Syntax

As the name suggests, pseudocode generally does not actually obey the syntax
Syntax

In linguistics, syntax is the study of the principles and rules for constructing Sentence s in natural languages. In addition to referring to the discipline, the term syntax is also used to refer directly to the rules and principles that govern the sentence structure of any individual language, as in "the Irish syntax"....
 rules of any particular language; there is no systematic standard form, although any particular writer will generally borrow style and syntax for example control structures from some conventional programming language. Popular syntax sources include Pascal, BASIC
BASIC

In computer programming, BASIC is a family of high-level programming languages. The Dartmouth BASIC was designed in 1964 by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire, United States to provide computer access to non-science students....
, C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
, C++
C++

C++ is a general-purpose programming language. It is regarded as a middle-level language, as it comprises a combination of both high-level programming language and low-level programming language language features....
, Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, Lisp
Lisp programming language

Lisp is a family of computer programming languages with a long history and a distinctive, fully parenthesized syntax. Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older....
, and ALGOL
Algol

Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered....
. Variable declarations are typically omitted. Function calls and blocks of code, for example code contained within a loop, is often replaced by a one-line natural language sentence.

Depending on the writer, pseudocode may therefore vary widely in style, from a near-exact imitation of a real programming language at one extreme, to a description approaching formatted prose at the other.

Examples


 = 

if do stuff else do other stuff

while do stuff

for from to by do stuff with variable

function () do stuff with arguments return something

() // Function call


For more examples, see articles with example pseudocode.

Mathematical style pseudocode

In numerical computation, pseudocode often consists of mathematical notation
Mathematical notation

A mathematical notation is a system of symbolic representations of mathematical objects and ideas. Mathematical notations are used in mathematics and the physical sciences, engineering and economics....
, typically from set
Set theory

Set theory is the branch of mathematics that studies Set , which are collections of objects. Although any type of object can be collected into a set, set theory is applied most often to objects that are relevant to mathematics....
 and matrix
Matrix (mathematics)

In mathematics, a matrix is a rectangular array of numbers, as shown at the right. In addition to a number of elementary, entrywise operations such as matrix addition a key notion is matrix multiplication....
 theory, mixed with the control structures of a conventional programming language, and perhaps also natural language
Natural language

In the philosophy of language, a natural language is a language that is spoken, Sign language, or writing by humans for general-purpose communication, as distinguished from formal languages and from constructed languages....
 descriptions. This is a compact and often informal notation that can be understood by a wide range of mathematically trained people, and is frequently used as a way to describe mathematical algorithm
Algorithm

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing....
s.

Normally non-ASCII
ASCII

American Standard Code for Information Interchange , is a coding standard that can be used for interchanging information, if the information is expressed mainly by the written form of English words....
 typesetting
Typesetting

Typesetting involves the presentation of textual material in graphic form on paper or some other Recording medium. Before the advent of desktop publishing, typesetting of printed material was produced in print shops by compositors or typesetters working by hand, and later with machines....
 is used for the mathematical equations, for example by means of TeX
TeX

TeX is a typesetting system designed and mostly written by Donald Knuth. Together with the METAFONT language for font description and the Computer Modern typefaces, it was designed with two main goals in mind: to allow anybody to produce high-quality books using a reasonable amount of effort, and to provide a system that would give the exact...
 or MathML
MathML

Mathematical Markup Language is an application of XML for describing mathematics notations and capturing both its structure and content. It aims at integrating mathematical formulae into World Wide Web documents....
 markup, or proprietary formula editor
Formula editor

A formula editor is a name for a computer program that is used to typeset mathematical works or formulae.Formula editors typical serve two purposes:...
s.

Mathematical style pseudocode is sometimes referred to as pidgin code, for example pidgin ALGOL
Algol

Algol , known colloquially as the Demon Star, is a bright star in the constellation Perseus . It is one of the best known eclipsing binary, the first such star to be discovered, and also one of the first variable stars to be discovered....
 (the origin of the concept), pidgin Fortran
Fortran

Fortran is a general-purpose programming language, procedural programming language, imperative programming language programming language that is especially suited to numerical analysis and scientific computing....
, pidgin BASIC
BASIC

In computer programming, BASIC is a family of high-level programming languages. The Dartmouth BASIC was designed in 1964 by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College in New Hampshire, United States to provide computer access to non-science students....
, pidgin Pascal
Pascal (programming language)

Pascal is an influential imperative programming and Procedural programming programming language, designed in 1968/9 and published in 1970 by Niklaus Wirth as a small and efficient language intended to encourage good programming practices using structured programming and data structure....
, pidgin C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
, and pidgin Ada
Ada (programming language)

Ada is a structured programming, statically typed, Imperative programming, and Object-oriented programming high-level language computer programming programming language, extended from Pascal and other languages....
.

Machine compilation or interpretation

It is often suggested that future programming languages will be more similar to pseudocode or natural language
Natural language

In the philosophy of language, a natural language is a language that is spoken, Sign language, or writing by humans for general-purpose communication, as distinguished from formal languages and from constructed languages....
 than to present-day languages; the idea is that increasing computer speeds and advances in compiler technology will permit computers to create programs from descriptions of algorithms, instead of requiring the details to be implemented by a human.

Natural language grammar in programming languages

Various attempts to bring elements of natural language grammar into computer programming have produced programming languages such as HyperTalk
HyperTalk

HyperTalk is a high-level, Procedural programming programming language created in 1987 by Dan Winkler and used in conjunction with Apple Computer's HyperCard hypermedia program by Bill Atkinson....
, Lingo, AppleScript
AppleScript

AppleScript is a scripting language devised by Apple Inc., and built into Mac OS. More generally, "AppleScript" is the word used to designate the Mac OS scripting interface, which is meant to operate in parallel with the graphical user interface....
, SQL
SQL

SQL is a database computer language designed for the retrieval and management of data in relational database management systems , database schema creation and modification, and database object access control management....
 and Inform
Inform

Inform is a programming language and design system for interactive fiction originally created in 1993 by Graham Nelson. Inform can generate programs designed for the Z-machine or Glulx virtual machines....
. In these languages, parentheses and other special characters are replaced by prepositions, resulting in quite talkative code. This may make it easier for a person without knowledge about the language to understand the code and perhaps also to learn the language. However, the similarity to natural language is usually more cosmetic than genuine. The syntax rules are just as strict and formal as in conventional programming, and do not necessarily make development of the programs easier.

Mathematical programming languages

An alternative to using mathematical pseudocode (involving set theory notation or matrix operations) for documentation of algorithms is to use a formal mathematical programming language that is a mix of non-ASCII mathematical notation and program control structures. Then the code can be parsed and interpreted by a machine.

Several formal specification language
Specification language

A specification language is a formal language used in computer science.Unlike most programming languages, which are directly executable formal languages used to implement a system, specification languages are used during systems analysis, requirements analysis and systems design....
s include set theory notation using special characters. Examples are:
  • Z notation
    Z notation

    The Z notation , named after Zermelo-Fr?nkel set theory ? J.R. Abrial answers the question "Why Z?" with "Because it is the ultimate language!" ? , is a Formal specification specification language used for describing and modeling computing systems....
  • Vienna Development Method
    Vienna Development Method

    The Vienna Development Method is one of the longest-established Formal Methods for the development of computer-based systems. Originating in work done at IBM's Vienna Laboratory in the 1970s, it has grown to include a group of techniques and tools based on a formal specification language - the VDM Specification Language ....
     Specification Language (VDM-SL).


Some array programming languages include vectorized expressions and matrix operations as non-ASCII formulas, mixed with conventional control structures. Examples are:
  • A programming language (APL), and its dialects APLX
    APLX

    APLX is a modern, second generation, cross-platform programming language dialect of the APL programming language. APLX is targeted at applications such as financial planning, market research, statistics, management information, and various kinds of scientific and engineering work....
     and A+
    A+ (programming language)

    A+ is an array programming language, a dialect of APL with aggressive extensions. Arthur Whitney developed the "A" portion of A+, while other developers at Morgan Stanley extended it, adding a graphical user interface and other language features....
    .
  • MathCAD.


See also

  • Short Code
    Short code

    Short codes, also known as short numbers, are special telephone numbers, significantly shorter than full telephone numbers, which can also be used to address Short message service and Multimedia Messaging System messages from mobile phones or fixed phones....
  • Dummy code
    Dummy code

    In computer programming, dummy code is inserted in a Skeleton to simulate processing and avoid compiler error messages. It may involve empty subroutine declarations, or functions that return a correct result only for a simple test case where the expected response of the code is known....
  • Pidgin code
  • Program Design Language
    Program Design Language

    Program Design Language is a method for designing and documenting methods and procedures in software. It is related to pseudocode, but unlike pseudocode, it is written in plain language without any terms that could suggest the use of any programming language or library....
     (PDL)
  • Skeleton program
  • Structured English
    Structured English

    Structured English is a the use of the English language with the syntax of structured programming. Thus structured English aims at getting the benefits of both the programming logic and natural language....
  • Concept programming
    Concept programming

    Concept programming is a programming paradigm focusing on how concepts, that live in the programmer's head, translate into representations that are found in the code space....


External links

  • , PDF file.
  • base on data from Code Complete book