Side-Quest: Writing Pseudocode

Introduction

Today, I’d like to introduce you to a series of posts outside the main series: side-quests! Side-quest posts allow me to talk about other topics not directly tied to building a complete game or set of sequential posts.

For this side-quest, I want to talk about pseudocode, what it is, and how/when I use it.

Ready? Let’s go.

What is Pseudocode?

Pseudocode is a form of planning and documenting your thoughts; step by step. It’s the written steps of an algorithm or breakdown set of tasks written in plain language, meaning it’s written to be as easy to read and understand as possible.

The goal is to avoid syntactical details of programming languages and focus on getting the idea from your head to the screen as quickly as possible to document the steps of an algorithm.

In music, this would be the equivalent of recording a quick scratch track of an idea as soon as the inspiration and melody come to mind. Later, it can be a reference as you build on the scratch track for a complete song concept.

How I Write It

I use pseudocode anytime there’s a new algorithm or a variation that I need to plan. I go through these stages:

Pseudocode > Replace > Refactor

Let’s use a simple contrived example for the sake of this post. What if we want to use pseudocode to plan a merchant display inventory and asking the player to buy?

We can break that down into three high-level steps: get the inventory items, display them, and pose the question to the player. There would undoubtedly be a lot more involved here in an actual game, but again, let’s keep it simple for demonstration.

Store Pseudocode

Now we can begin implementation for each line of pseudocode.

Store Code

Finally, we can remove the pseudo comments and refactor the code as necessary to ensure the correct level of abstraction and separation of concerns.

Summary

I hope you enjoyed this short side-quest of the week. I’ll have more of this as we continue forward. I believe this would be a great way to introduce language specifics and other topics, like music and math, alongside the main weekly posts.

What are your thoughts? Let me know!
Take care.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s