There are a plethora of things you can do to make yourself a better coder. If you’ve made coding your career then you owe it to yourself to become the best you can be and one of those things is using Pseudo Code.
What is Pseudo Code?
Pseudo code is a simplified version of an algorithm or block of logic that is easy to understand. It is a method to layout easy to read programming logic to speed up design and make it easier for programmers and non-programmers to comprehend.
How do I write Pseudo Code?
The first thing to do when you write a new application is to organize your thoughts and write pseudo code. Pseudo code is an informal high-level description of an algorithm, routine or a unit of work. Don’t confuse pseudo code with real code because syntactically, it will not compile. So why write pseudo code when you can write real code? The reason is because you want to plan out your approach before writing a single line of code. Another reason is because you may want to detail out your work before committing to the programming language that you will be writing the application with. Planning goes a long way for medium-sized to larger applications.
Some of my best friends who are coders in the industry will write a page of pseudo code first before they commit to a single line of real code. The reason they do this is because it helps organize their thoughts and the application as a whole. They use pseudo code as placeholders for the real code that they will fill in later. By using pseudo code, they are actually structuring the application and providing a roadmap, just in case they have to hand it off to another coder or have a team of coders work on the application together.
In some circumstances, senior coders will write ‘hints’ or ‘clues’ in their pseudo code to help beginner coders write better applications. When I was starting out as a coder, I remembered coding a complex billing application where the formulas were embedded in the pseudo code. This helped my coding efforts tremendously, reducing the time to code it and the pseudo code remained in the application as descriptive comments that helped software testers confirm the correctness of the code.
Recommended Training – Treehouse
Although this site recommends various training services, our top recommendation is Treehouse.
Treehouse is an online training service that teaches web design, web development and app development with videos, quizzes and interactive coding exercises.
Treehouse's mission is to bring technology education to those who can't get it, and is committed to helping its students find jobs. If you're looking to turn coding into your career, you should consider Treehouse.
Pseudo Code Examples
It is easy to write pseudo code and there are only a few rules to follow.
Comment your pseudo code
Prefix the line with a comment symbol so that the compiler ignores the line. If you write pseudo code properly, you won’t have to come back and rewrite it when you are finished writing your application. Good comments go a long way when maintaining and supporting code.
Eg. In Python, use the hashtag symbol for comments.
# This block of code will parse out the email address of the sender. # This block of code will formulate a reply to the sender to thank them.
Use Normal Words
Try to stay away from using words associated with a computer language or jargon. Use descriptive words and explain the intent of the code that lies ahead.
Eg. In Python, it’s better to explain in easy English what the intent is.
# Extract the third element as my favorite car.. Cars = np.array[‘BMW’, ‘Chevy’, ‘Suburu’] Favorite = cars
Indent or use the tab key if the block of work is going to be repeated or depends on a condition.
Eg. Indent your pseudo code when using loops.
# Initialize list. All_lists = [[1, 2, 3], [4, 5, 6]] # Iterate through each list. For list in All_lists: # Iterate through each item. For x in list: # Do something with x Print x EndFor EndFor
Writing pseudo code is a good habit to adopt because it will ultimately make you a better coder. In my experience, I have seen thousands of lines of code that were never commented with pseudo code or any comments whatsoever. It made the job of maintaining code extremely difficult and risky to modify. In my opinion, It is the responsibility of the coders to document their own work and the better the comments are, the easier the code is to be maintained. It is short-sighted to think that applications will never have to be changed. When something changes, applications fail and coders are hired to modify code.
Be a responsible coder and make it easier for coders who have to support applications with good, descriptive pseudo code. If you follow this advice, your applications will be better organized and better written.
Disclosure of Material Connection: Some of the links in the post above are “affiliate links.” This means if you click on the link and purchase the item, I will receive an affiliate commission. Regardless, I only recommend products or services I use personally and believe will add value to my readers.