Programming Basics #36 Writing Pseudocode


writing pseudo code there are a few steps you may consider
before you start to write a program step one is to get away from the
computer grab a piece of paper or a whiteboard and start writing what’s
called pseudo code pseudocode it’s not a language is the
term for writing your computer instructions in plain English to the point where it’s readable by
anyone who understands the problem whether they can program or not let’s see some examples so in a
whiteboard or paper we may write something like this ask use your free email address if email
address matches accepted pattern add them to email list else show error
message something like this pseudocode don’t
have formal rules know where I said ask user per email
address I could have said get the email address or prompt for
email address or if I wanted to break it out I could
say create email variable ask user for email address store users
email address in email variable or I could just say get the email I’m just trying to define the structure
up this code what has to happen in my problem and is comin to C programming keywords
like if else while and four but it’s whatever
makes sense and you also see pseudocode of an
indented like I have done here and like any
indentation it’s just make it easier to follow the
structure now different people write pseudocode in
different ways some pseudo code tends to take the style of the language sometimes you will see written partly in
upper case like this and it’s quite common to see people
explicit marking where and if or loop ends using a phrase like
and if or end loop the same purpose here is the
opening and closing curly braces in JavaScript or sea bass blink which the point is clarity and understanding
can you read the pseudocode does that make sense here’s an example perhaps up going
through a list of numbers and adding him together in pseudocode the Allpoint this to get
away from braces practices rackets off by one errors naming conventions its whatevers seems
natural now it doesn’t necessarily break down to
one lineup pseudocode one-liner real code sometimes one lineup
pseudocode could cause several lines have real code one of the best things up pseudocode is
it let you think about your problem without necessarily knowing how exactly
quoted let’s say I’m trying to build a game and
I know how to work with images so I might write some pseudo code like
this: if a missile image touches the spaceship image well I’m going to replace the space ship
with the explosion image then I want to play an explosion sound
and then I better check is the remaining lives counter to zero because if it is I’m a show the game
over message it’s not zero I subtract one from the
remaining lives I show begin message i reset the
spaceship to starting position et cetera et cetera 0 soon code is not only for beginners many very
experiences software developers still work out a lot of their problems in
pseudocode in a way a better understanding it
without worried about its syntax it’s a great habit to get into to start
sketching your programming ideas in plain English before you write code

Leave a Reply

Your email address will not be published. Required fields are marked *