Tools Links Login

Making Life Easier with Pseudo Code

The purpose of this article is to introduce you to the world of Pseudo Code and help you improve your development skills.

Original Author: D Davis

Code





Making Life Easier
  with Pseudo Code


  By: Dustin Davis (Programmers-Unlimited.com)










Introduction
Pseudo Code is not
  a programming language in specific, but it is a language specific to your
  native tongue (English, Spanish, etc.). It is a type of "modeling"
  tool that will be a great friend to you in future projects. By using non
  code specific terms and phrases, applications written in Pseudo Code can
  easily be understood by multiple developers, and if written well enough,
  can be used to translate applications to different platforms and programming
  languages. This means a great deal to anyone who has experience in developing
  on a tight time table.


  In basic terms, Pseudo Code is the english (or whatever) version of real code. Let's take a look at some Pseudo Code.











Getting
  Started

  

Getting started is
  the hard part as it requires that you have an idea that has been thought
  out. A word of advice is that you should never wait until you have 100%
  of your project worked out. If you do, you will most likely never start.
  For this article, we will design a simple program to emulate a Pay Phone.


  

The first step we
  need to take is designing and overall general program flow. A Pay Phone
  is pretty easy to do as it does not have much to it.

  

  


  
  
  
  
  

  

        
  • Wait for
        user

  •     
  • Take money

  •     
  • Take input

  •     
  • Make call

  •   

  

  

Pretty simple eh?
  Like I said, not much to a Pay Phone. So now we have an overall general
  view of what we need to do, let's get moving with the next step.

  












Breaking
  Down the Overall Process
The next thing to do
  is go back over the overall general view that we created. We will take each
  step and break it down into working Pseudo Code.

  

  "Wait for user"

  This process could contain anything depending on the phone. Most phones
  are just dead, but some of the newer phone have LCD's that display all sorts
  of things. In this example, let's just make it simple

  

  

  
  
  
  
  

  

Function "Wait
    for user"


  

    

Get Time

    Display Time On LCD

    

    Check For Input


    

    

If coins
     are inserted, call "Take money"

     If buttons are pushed, call "Take input"


    

  

  

End Function
    "Wait for user"


  

  



  wow, that's it?! Pretty much. Obviously, anyone who has ever worked with
  LCD's will know there are more steps involved in displaying the time on
  the screen, but that's the good part, and we will get to that later.


  

On the first line,
  we define a function. Anyone who reads this will be able to tell that
  the following will be inside of the "Wait for user" function.
  On the following line, you will see "Get Time". This tells the
  reader that the code for getting the time will go in that spot, before
  "Display Time On LCD". We continue writing the parts of the
  function that it will contain. Notice that it's easy to read compared
  to code? This is the power of Pseudo Code.


  

Using Pseudo Code,
  we have just created a template for our "Wait for user" function.
  This template will allow anyone to come back to it and fill it in with
  code of their choice.


  

"Take money"
  , "Take input"

  Every Pay Phone has to take money and input. The functions are (in a general
  breakdown) very simple.

  


  
  
  
  
  

  

Function "Take
    money"


  

    

Wait For
    Coin Insert

    


    

Identify
    Coin


    

    

If coin
     is invalid, return to change drop

     otherwise, increase users balance


    

  

  

End Function
    "Take money"


  

Function "Take
    input"


  

    

Identify
    Button Pushed


    

    

If invalid
     button (#,*) then return money and disconnect call

     If valid button, add digit to the phone number


    

    

Check For
    a Valid Number


    

    

If a
     valid number has been input, call "Make call"

     Otherwise, return change and disconnect call


    

  

  

End Function
    "Take input"


  

  

These functions are
  pretty simple and are no different from our "Wait for user"
  function. These functions are simply templates for later code insertion.


  

"Make call"

  Our make call function will be a little bigger than the previous functions,
  let's dig in...


  
  
  
  
  

  

Function "Make
    call"

    


  

    

Get Cost
    of Call


    

    

If user
     has not inserted enough coins, tell them to insert the remaining
     balance, Call "Take money"


    

    

Dial Number


    

Wait For
    Connection


    

    

If busy,
     return change to coin drop

     otherwise, store coins in bank


    

    

Wait For
    Disconnect


    

    

On disconnect,
     call "Wait for user"


    

  

  

End Function
    "Make call"


  

  

I just want to clarify
  that I am no phone technician and I know that there are many many more
  operations to a Pay Phone, but this is what we have for this article.
  Let's move on to the next section.












Further
  Breakdown

  

Now that you understand
  that Pseudo Code is crazy simple, let's get into some specifics. We will
  go back to our "Wait for user" function. We are going to modify
  it so that when you assign it to your programmer, he will understand exactly
  what you want.


  
  
  
  
  

  

Function "Wait
    for user"


  

    

(start loop)

    Get Time

    Display Time On LCD

     - Scroll time from left to right

     - Format: HH:MM AM/PM

    

    Check For Input

     - Check coin drop for coin insert

     - Check keypad buffer for button push


    

    

If coins
     are inserted, call "Take money"

     If buttons are pushed, call "Take input"


    

    

(end loop)


  

  

End Function
    "Wait for user"


  

  

You think I'm a crazy person
   who's toying with you now, don't ya?! I'm serious, this is how easy Pseudo
  Code can be. You can modify your Pseudo code to look as you like, just
  keep in mind the readability for others (if any at all).












Conclusion

  

The power of Pseudo
  Code can be from 0 to unlimited. It all depends on you and your methods.
  Pseudo Code can scale the ease of transition from Pseudo Code to Real
  Code depending on how you use it. If you use more programming language
  specific articles, you will have an easier time porting it into real code.
  In most cases, Pseudo Code can be directly replaced with code with little
  to no extra thinking.

  

  I hope this article has been helpful and I hope it helps you to write
  better code. By using Pseudo Code, it can help see issues that would normally
  not be seen by looking at real code since you are reading it in your native
  tongue.

  

  Check out more articles like this on Programmers-Unlimited.com.



About this post

Posted: 2003-06-01
By: ArchiveBot
Viewed: 90 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.