Intro to the world of pseudocode:
It is common in computer science to use a technique called pseudocode that explains in plain English the steps contained in an algorithm or another system. Unlike normal programming languages, pseudocode is designed to be read by humans as opposed to by machines. It is an informal, artificial language that can be used by programmers to create algorithms. Most of the rules of pseudocode are straightforward and convenient to solve problems systematically and efficiently for any field that has problems to solve.
How can we use Pseudocode?
Pseudocode is used to formalize steps taken to solve a problem, in this case, an algorithm.
Let's imagine that we want to find a long-lost friend of ours in the phonebook, and the only thing we know is that their name starts with a J.
One solution would be to flip every page in the book from start until we arrive on the J page, but that would take too long and not be efficient at all.
Another solution would be to flip in the middle of the book, then access if j is on the left side of the book or right side and then flip towards the appropriate side in the middle again, and do this until we find the J page this would be a more efficient way to find the J page in the phone book.
Let's formalize the pseudocode for the second algorithm.
1 Pick up the phone book
2 Open to the middle of the phone book
3 Look at the page
4 If the page is J page
5 Call long lost friend
6 Else if J page is earlier in the book
7 Open to the middle of the left half of the book
9 Go back to line 3
10 Else if J page is later in the book
11 Open to the middle of the right half of the book
12 Go back to line 3
13 Else(if J page doesn't exist)
14 Quit
Now, the last part of quitting is important when writing a computer program because it gives clarity to the computer and eliminates chances for bugs and crashes by eliminating undefined behavior.
Why should we use pseudocode at all?
-Improved readability.
-It will also make code construction easier.
-Ideal as a middle ground between flowcharts and code.
-Serve as a starting point for documentation.
-Makes finding and fixing bugs easier.
Rules of writing pseudocode
As pseudocode is read by humans and not by a computer, everyone has a unique way of presenting things out, as its rules are less rigid than those of a programming language. However, some simple rules help make pseudocode more universal.
-Make sure to capitalize the first word.
-Limit the number of statements per line to one.
-Show hierarchy, improve readability and show nested
constructs with indents.
-Programming language independence is key.
-Names should reflect the problems.
-Be clear, concise, and readable.
Final thoughts
Pseudocode is widely used in programming and software/web development but it is a great tool for anyone that needs a good and systematic way to solve problems as long as the steps taken to a solution can be identified.
It brings clarity and minimizes risks for bugs and is a great start for your documentation. The more comfortable we become making pseudocode the easier it is to see the silver linings in problems at hand.
I hope you got some clarity out of this, if you have anything to add, then leave a comment below. Thanks
Top comments (0)