Skip to main content

The Cheeky Monkey Media Blog

A few words from the apes, monkeys, and various primates that make up the Cheeky Monkey Super Squad.

Pseudocode Programming

Pseudocode Programming

Before writing any actual code for a module or project, you should try to construct your code idea in a low language(Plain English), which is a good practice.Then, when you write the actual code, the steps will be clear and automatic to create. A great benefit to this is that you have now a comments section to add over your code so future programmers will grasp the code easily.

Lets look at an example:

  1. PROGRAM MakeDoubleDoubleCoffee:
  2.     Organize everything together;
  3.     Add coffee in coffee machine;
  4.     Add water to coffee machine;
  5.     Start coffee machine;
  6.     Pour coffee into cup;
  7.     Add two sugars;
  8.     Add two creams;
  9.     Serve;
  10. END

This is a straightforward program for making coffee. Now what if you don’t like sugar ? We need to add a condition into the Pseudocode for that:

  1. PROGRAM MakeDoubleDoubleCoffee:
  2.     Organize everything together;
  3.     Add coffee in coffee machine;
  4.     Add water to coffee machine;
  5.     Start coffee machine;
  6.     Pour coffee into cup;
  7.     IF ( sugar is required )
  8.         THEN Add two sugars;
  9.         ELSE don’t add two sugars;
  10.     ENDIF
  11.     Add two creams;
  12.     Serve;
  13. END

 

What if we want a loop in this program? Let’s say we want to fill the cup until its full. I really love coffee…

  1. PROGRAM MakeDoubleDoubleCoffee:
  2.     Organize everything together;
  3.     Add coffee in coffee machine;
  4.     Add water to coffee machine;
  5.     Start coffee machine;
  6.     WHILE (coffee cup is not full)
  7.         Do keep filling cup of coffee;
  8.     END WHILE
  9.     IF (sugar is required)
  10.         THEN Add two sugars;
  11.         ELSE don’t add two sugars;
  12.     ENDIF
  13.     Add two creams;
  14.     Serve;
  15. END

There it is. A program that fills up your cup of coffee and adds sugar if requested.

Pseudo code is plain, simple and easy. You don’t need a background in computer programming to understand; therefore allowing developers to bring non-programmers (like the clients) into the development stages and benefiting from their input on things and helping to formulate their own end product.

It isn’t a programming language, but it can be used with ANY programming language. Some languages are better for certain tasks. Using pseudocode is a good alternative to getting the work started and not wasting any development time.

Believe it or not,s there are programming language that resembles pseudocode a lot. They are called “Behat” and “Cucumber” … weird names I know.

Let’s look a Behat. Behat is a Behaviour-driven development framework and works with PHP. The way the framework works is by writing human-readable sentences that outlines the features and how it works, then writing some behaviour behind these human sentences.

Here is an example taken from the Behat website:

Imagine you’re about to create the famous UNIX “ls” command. Before you begin, you describe how the feature should work:

Feature: ls

 In order to see the directory structure, as a UNIX user I need to be able to list the current directory's contents.

  1.  Scenario:
  2.    Given I am in a directory "test"
  3.    And I have a file named "foo"
  4.    And I have a file named "bar"
  5.    When I run "ls"
  6.    Then I should get:
  7.      """
  8.      bar
  9.      foo
  10.      """

In the example above, we can see that it resembles pseudocode a lot. Cucumber is almost very similar.

Pseudocode and Behat are powerful approaches to programming and fun to use. Here are some pages to look at for more behat information:

Web Development

Would you like to know more about what we do?

View Our Services

Graphic Design Cheeky Monkey

Have a look at some our client work

View Our Work

Cheeky Monkey Discovery

Learn more about Cheeky Monkey Media

About Us

Comments