Pseudocode: Difference between revisions
No edit summary |
→Description: fixed run-on sentence |
||
Line 3: | Line 3: | ||
==Description== |
==Description== |
||
As the name suggests, pseudocode generally does not actually use the [[syntax]] of any particular language; there is no systematic standard form, although any particular writer will generally borrow the appearance of a particular language |
As the name suggests, pseudocode generally does not actually use the [[syntax]] of any particular language; there is no systematic standard form, although any particular writer will generally borrow the appearance of a particular language. Popular sources include [[ALGOL]], [[C programming language|C]], and [[Lisp programming language|Lisp]]. Details not relevant to the algorithm (such as [[memory management]] code) are usually omitted, and the programming language will be augmented with [[natural language]] where convenient (for example, for trivial operations such as swapping two variables). 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. |
||
[[Flowchart]]s can be thought of as a graphical form of pseudocode. |
[[Flowchart]]s can be thought of as a graphical form of pseudocode. |
Revision as of 04:30, 2 November 2005
Pseudocode is a generic way of describing an algorithm using the conventions of programming languages, without using language-specific syntax.
Description
As the name suggests, pseudocode generally does not actually use the syntax of any particular language; there is no systematic standard form, although any particular writer will generally borrow the appearance of a particular language. Popular sources include ALGOL, C, and Lisp. Details not relevant to the algorithm (such as memory management code) are usually omitted, and the programming language will be augmented with natural language where convenient (for example, for trivial operations such as swapping two variables). 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.
Flowcharts can be thought of as a graphical form of pseudocode.
Applications
Computer science textbooks often use pseudocode in their examples so that all programmers can understand them, even if they do not all know the same programming languages. 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 general-purpose languages—for example, Knuth's seminal textbook The Art of Computer Programming describes algorithms in a fully-specified assembly language for a non-existent microprocessor.
A programmer 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.
Examples of pseudocode
A PHP code stub
An example of how pseudocode differs from regular code is below.
Regular code (written in PHP):
<?php if ($foo == "bar") { $yesFoo = true; } else { $yesFoo = false; } ?>
Pseudocode:
If the value of foo is equal to bar then make "yesFoo" true otherwise, make "yesFoo" false
A BlitzBasic code stub
A similar example to the preceding one is shown below.
Regular code (written in BlitzBasic):
if foo$="bar" yesFoo=True else yesFoo=False endif
Pseudocode:
if the value of foo is equal to bar then make "yesFoo" true otherwise, make "yesFoo" false
Compilation
It is often suggested that future programming languages will be more similar to pseudocode or natural language 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. Various attempts to bring this about have produced programming languages such as Visual Basic and Applescript; in practice, however, the similarity to natural language is usually more cosmetic than genuine, and any increased simplicity in use is due to powerful libraries, not to any intelligence on the part of the compiler.