VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Making Life Easier with Pseudo Code

by D Davis (1 Submission)
Category: Coding Standards
Compatability: VB Script
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (10 Votes)

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

Rate Making Life Easier with Pseudo 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.


 
 

Download this snippet    Add to My Saved Code

Making Life Easier with Pseudo Code Comments

No comments have been posted about Making Life Easier with Pseudo Code. Why not be the first to post a comment about Making Life Easier with Pseudo Code.

Post your comment

Subject:
Message:
0/1000 characters