Thursday, October 6, 2016

Pseudocode

Introduction

Pseudocode is defined as structured english for describing algorithms. We've used pseudocode to express what we want our code to do without using proper java syntax, but there are specific rules to writing pseudocode to make it readable for other developers that we should be familiar with.

Image result for pseudo code

Basics

    One of the first skills we learned in 150 was how to instantiate variables to a certain type and value. In pseudocode, we use the phrase "set <variable name> to <value>" to show this code. We do not have to tell the reader what type the variable is since it's obvious to us by the value alone, unlike the computer. We can also represent calls to other functions by using the phrase "call <function> with/returning <variable>/<what it returns>". 

Representing Loops

     These "constructs" are keywords used to express how we want the program to flow through statements of code. A sequence is used as a representation of linear progression through a set of tasks. This can be used inside of a loop or on its own. To represent loops we use roughly the same jargon as it appears in java with an added "end" statement, representing when body inside of the loop ends. For a while loop we'd use the keywords while and endwhile, for if statements if-then-else and endif, for for loops for and endfor, for switch statements case and endcase, and for do-while repeat-until. These replacements translate java to a more english-based representation, making it easier for people to follow your program and see the beginning and end of loops without the use of brackets.

Uses

     Pseudocode is a way for you to express what you want your program to do without worrying about the rules of a specific programming language. It may be useful to you when planning out a program to first outline a plan for implementation, including what you want each function or piece of code to do, and then begin implementation with a language of your choice. Pseudocode might also help you comment your finished product so that a user can more clearly see your train of thought.


Sources
- http://users.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html
- http://guyhaas.com/bfoit/itp/Pseudocode.html

2 comments:

  1. Hi Ryan, great blogpost! Pseudocode is so often under-appreciated and over looked in coding and I am glad you wrote about it in your blog. Writing in pseudocode makes things so much easier when writing algorithms and is always a good start when trying to figure out a problem without having to worry about the stress of having correct java syntax.

    ReplyDelete
  2. Heh Ryan, I really enjoyed reading your post! Yeah pseudo code can be really useful in iterative design and in collaboration projects, as it can make the code clearer and planned out in a more organized way. For me, I haven't got into the habit of using pseudo-code regularly yet. But I imagine that it would be more useful for less expressive languages like Java or C than for Python or Lisp (which are pretty simplified already).

    ReplyDelete