Why you need to be writing Pseudocode!

addam davis
3 min readMay 7, 2021

--

If you have been following along from home, then you will have written some impressive lines of code so far. That’s great, and I want you to continue to write code and experiment with code. Because of that I think it’s the perfect time to introduce you to pseudocode.

Pseudocode is code that you type out in English as a comment and then you convert it into actual code.

When you are learning how to code, or you are attempting something new, it is good practice to write out what you are wanting to happen in pseudocode. As you write the pseudocode you will start to see how you need to write the actual code. Let’s run an example to help you further understand pseudocode.

Today we are going to look back at a previous lesson to show case what a pseudocode is and how you can use it to your benefit. When we added a starting position to our player we used the code.

To write this as a pseudocode you would write out what it is that you want to do. You start with // every code begins with the double forward slash. Then your text will turn green, and you can begin typing what you want.

Take the current position (set) new position, then your x, y, and z axis. Now we can see this and begin to convert this pseudocode into usable code. You want the current position, and to get that you must use the hierarchy of Unity. The position is in the transform component. So, you need to begin with the transform before you can get the position.

Transform.position, the equals sign means you want to set to a new position. You will remember that every time you are dealing with moving an object it will use a vector3 and every time you use a vector3 you will use the keyword new. Now we can continue with the other half of the code.

Transform.position = new vector3(0, 0, 0)

With using pseudocode and remembering the hierarchy of Unity you don’t have to memorize every code layout. If you get in the habit of writing pseudocode it can help you remember how to write code and keep your goal of said code highlighted for you.

Once you have you code written, and you are happy with it you can always remove the pseudocode and comments to declutter visual studio. However, it is always a good idea to leave a comment if you cannot understand the purpose of a code at a glance.

That is the gist of pseudocode, with this practice I believe you will be able to develop you coding skill quicker and learn the pattern to coding quicker. This is a short lesson, but and important one. Continue to practice and I’ll see you in the next one!

--

--