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
Getting started is The first step we Pretty simple eh? Function "Wait Get Time If coins End Function On the first line, Using Pseudo Code, "Take money" Function "Take Wait For Identify If coin End Function Function "Take Identify If invalid Check For If a End Function These functions are "Make call" Function "Make Get Cost If user Dial Number Wait For If busy, Wait For On disconnect, End Function I just want to clarify Now that you understand Function "Wait (start loop) If coins (end loop) End Function You think I'm a crazy person The power of Pseudo
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
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.
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.
user
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
for user"
Display Time On LCD
Check For Input
are inserted, call "Take money"
If buttons are pushed, call "Take input"
"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.
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.
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 input"
Every Pay Phone has to take money and input. The functions are (in a general
breakdown) very simple.
money"
Coin Insert
Coin
is invalid, return to change drop
otherwise, increase users balance
"Take money"
input"
Button Pushed
button (#,*) then return money and disconnect call
If valid button, add digit to the phone number
a Valid Number
valid number has been input, call "Make call"
Otherwise, return change and disconnect call
"Take input"
pretty simple and are no different from our "Wait for user"
function. These functions are simply templates for later code insertion.
Our make call function will be a little bigger than the previous functions,
let's dig in...
call"
of Call
has not inserted enough coins, tell them to insert the remaining
balance, Call "Take money"
Connection
return change to coin drop
otherwise, store coins in bank
Disconnect
call "Wait for user"
"Make call"
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
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.
for user"
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
are inserted, call "Take money"
If buttons are pushed, call "Take input"
"Wait for user"
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
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.
Loading Comments ...
Comments
No comments have been added for this post.
You must be logged in to make a comment.