Blogroll
The Pseudocode Programming Process
Pseudocode interesting technique that I found in Code Complete, Second Edition by Steve McConnell.
PPP is a way of developing routines by writing pseudocode for them in the first place (not a new topic) and after that, making the pseudocode a comment in the routine (functions, procedure, method or whatever your language calls them). After comments are in the empty routine, the
I know it isn't the clearest explanation, here look below at the example that I prepared.
We'll work on a routine responsible for query searching in a search engine (based on my very simple & ugly search engine.)
Magellan Maestro 3100 a best value GPS for vehicles, review
First, let's write the header comment for the routine:
-
// Searches for query in a set of pages, every word
-
// is searched independently, and then results of all
-
// search operations are concatenated.
Pretty simple, but should state what the routine will do. Next I will use a simple english statements as pseudocode and write the body of the routine:
-
// Searches for query in a set of pages, every word
-
// is searched independently, and then results of all
-
// search operations are concatenated.
-
-
// split query into separate words
-
// for each word in the query
-
// get pages containing the word
-
// from the database
-
-
// for each page
-
// if this page is in the score table
-
// add current word occurances on the
-
// page to the score table for given page
-
// if this page is not in the score table
-
// add the page to the score table
-
// and store current word occurances for
-
// this page in the score table
-
-
// create container for pages to return
-
// for each page in the score table
-
// retrieve page info from database and storei
-
// in the container
-
// return the container
It is not the most complicated routine in the word but will do.
Here's the code added for this routine:
-
// Searches for query in a set of pages, every word
-
// is searched independently, and then results of all
-
// search operations are concatenated.
-
-
function search($query, $from, $amount)
-
{
-
// split query into separate words
-
-
// for each word in the query
-
foreach ($words as $word)
-
{
-
// get pages containing the word from
-
// the database
-
$pages = $this->dataStore->getPagesWithWord($word);
-
-
// for each page
-
foreach ($pages as $id => $page)
-
{
-
// if this page is in the score table
-
{
-
// add current word occurances on the page
-
// to the score table for given page
-
$this->pages[$id]["score"] +=
-
$page["occurances"];
-
}
-
// if this page is not in the score table
-
else
-
{
-
// add the page to the score table
-
// and store current word occurances for
-
// this page in the score table
-
$this->pages[$id] = $page;
-
}
-
}
-
}
-
// create container for pages to return
-
// for each page in the score table
-
{
-
// retrieve page info from database and store in
-
// the container
-
$webPages[] = $this->dataStore->getPage($pageId);
-
}
-
// return the container
-
return $webPages;
-
}
The code above is in PHP but the same could be done for any other language, that's the beauty of pseudocode :) . You could give the pseudocode to some other programmer for a review and he doesn't have to know the lang in which it is written.
Some useful notes (once again taken from Code Complete, Second Edition) on how to write the pseudocode:
- use English-like words to describe the code
- do not use syntactic elements of the programming language
- the pseudocode should be written at the level of intent ("whats" not "hows")
- it should be enough low level to enable developer to write code based on it
That's it for this post, give me a hint if you liked the code, or better, try to write some more examples of the pseudocode.








thanks for the information………i think it would help our team in producing a good project.
Informative, not at all confusing.
Try it.
Very useful!!! Thanks a lot. It’s going to be of great help in for assignment
different from other examples… its detailed and easy to understand..
The whole pseudo Code is now commonly taught in college setting, programming basics and software engineering courses. It really allows you to visualize what the program will do and in what order. The hard part is learning the language well neough to make it do what you want.