Using Pseudo Code

 

We have already touched on pseudo code in this and in the previous lesson. Pseudo code is a nonstandard English like a programming language. It is English like because the logic statements read more like English sentences and phrases than what is typically found with programming language syntax. Program language statements and connecting syntax is much more cryptic and can take on the appearance of a mathematical equation. If you remember correctly from the previous lesson, I compared pseudo code to a recipe you might use to make chocolate chip cookies. Pseudo code is nonstandard because unlike programming languages which have very strict rules regarding keywords and syntax, there are no standards when it comes to pseudo code. As long as the statement is readable and defines what that logic step needs to accomplish, it is acceptable as pseudo code.

 

Keywords: Programming statements contain keywords. The keywords are typically verbs identified in that programming language to perform an operation. The keyword might be a verb print or input. Each language has its own set of keywords but it is not unusual for some keywords to exist throughout multiple languages. The if keyword is almost universal in all programming languages and allows us to program decisions into our logic.

 

Pseudo Code Rules:

 

The Advantages of Pseudo Code

 

The primary advantage of pseudo code comes from the fact that it is a programming language. It's a very simple and unstructured programming language and it is very easy to transition pseudo code to a programming language. Since we want our models to represent the best of all possible solutions, pseudo code probably requires the least amount of modification from model to actual program. Whereas a flowchart may represent a perfect world solution it might not be easily implemented into a program. Pseudo code can be more easily transitioned so it is more likely that our model logic will be very close to the implemented program.

 

Another advantage may be in its simplicity. It may take some time for a programmer to learn a new programming language but since pseudo code is so familiar and similar to reading instructions (i.e. recipe), it does not involve a steep learning curve. If you can read and write you can create pseudo code and understand pseudo code instructions.

 

The Disadvantages of Pseudo Code

 

The disadvantages of pseudo code may start with its lack of standards. One person's logic instructions may not seem as logical as the next. Given the unstructured nature of pseudo code, it is few rules and is hard to standardize. One programmer might not see the logic written by someone else.

 

Another disadvantage over other modeling tools like flowcharts may be pseudo codes inability to show logic flows or the bigger picture. Whereas flowcharts provide an overview of logic and can be understood at a higher level, pseudo code is far more detail oriented and requires more concentration and practice to see the bigger picture. Put another way, pseudo code focuses more on the details and the graphics of flowcharts allow for a 10,000 foot big picture perspective.

 

Pseudo Code Example

 

Using the problem and requirements from the flowchart section of the lesson we now put together a pseudo code representation of the logic design.

 

In Practice: Pseudo Code is Recyclable - Using Pseudo Code for Program Comments - Even when students understand the importance of creating logic models they are reluctant to use pseudo code because they're not sure that it adds value to their programming. Most would tell you that pseudo code slows them down and in their impatience; they will start their programming without it. But there is a way to recycle your pseudo code from your logic model into your program design and get more out of your pseudo code. Pseudo code is very similar to program comments. A program comment is a non-executable statement that is inserted into a program to give the programmer information about how the program is constructed. It is very specialized documentation left for the next programmer to clarify the programs design. There's no reason why the pseudo code could not be the basis of your source code comments. As you develop your program and implement the pseudo code into language statements, why not copy the pseudo code down into the program and use the pseudo code as the comment. In PYTHON for example, you could take the pseudo code and place a # sign in front of each pseudo code statement so it now becomes a program comment. This way you'll be able to recycle your pseudo code back into the program and it may not longer seem like a wasted step.

 

 

Status Check

What are the benefits and weaknesses of pseudo code?

Name some pseudo code rules?

It is said that pseudo code is more "English" like. What does this mean?

 

 

 


Click to close