Pseudocode-o

As a programmer, it can be extremely easy to absorb yourself in your code while you are trying to debug what the heck is going on in your code. After all, you did think about your code carefully before you tried typing right… Well, the answer to that question should be yes regardless of whether you wrote down any pseudocode! However if you don’t know what pseudocode is, wikipedia says the following:

Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm. It uses the structural conventions of a normal programming language, but is intended for human reading rather than machine reading.

Basically…

Basically, pseudocode is written english that should be directly translatable to code! Now I don’t mean directly translatable in the sense that you would be able to write pseudocode and then plug that into google translate with your programming language of choice (though that sounds kind of useful…), I mean that your pseudocode should contain a basic description of how your code should flow and function. Pseudocode is often an algorithm, or a series of instructions, that really provides structure to what you will programming and how to do it. It is like explaining what you are trying to program without using programming terms. If you can’t explain in words exactly what you are trying to do in pseudocode, then don’t try to write any code yet! And once you have properly created your pseudocode, it should be pretty simple to convert it into actual code.

How I feel about Ruby

Why Pseudocode?

  1. Pseudocode presents a solution to a programming challenge in English (or whatever language you choose to speak in)! This pseudocode can then be understood by non-programmers and thus you, the developer, can involve non-programmers into the creative process that is coding.
  2. Pseudocode is language independent! Say you had a friend that was working on the same problem as you but didn’t know the same programming language, you would then be able to share your ideas through the pseudocode you prepared! Also, while you may only know one language while learning how to program, pseudocode is beneficial for when you know multiple languages and are spending time deciding which language you may want to use to solve your current programming problem.
  3. Pseudocode allows developers to properly allocate their time on a project and streamline the product development phase. You can be sure that you have adequately defined your problem through pseudocode, before diving too deep into the actual implementation and then realizing you have forgotten something important. You also don’t waste time correcting code that has already been written.
  4. Pseudocode increases efficiency in a project’s development process. Projects can be developed quickly and thoroughly through pseudocode. Catching errors while writing pseudocode is less costly than catching them later in the development process.

PALINDROMES!

I wish the word palindrome was actually a palindrome…

I wanted to show you an implementation of how to determine whether a word is a palindrome in order to show you the importance and usefulness of pseudocode. To determine whether a word is a palindrome, you just simply refer to the definition: a palindrome is a word that reads the same forwards and backwards. Okay… that’s a good starting point, but how can we turn that into pseudocode. We could simply write something like:

def palindrome?(word)
word == word.reverse
end

But lets say there weren’t a reverse method. We’d have to build off the definition then. Well, diving deeper into what a palindrome is, a palindrome is a word that begins and ends with the same letter. When those two letters are removed, the remaining letters form a word that can also be read the same forwards and backwards, or in other words, when the two letters are removed, the remaining letters form a word that is also a palindrome. Great! We have a nice pseudocode algorithm to translate into code!

Pseudocode gets translated into ruby code

Above I translated the pseudocode into ruby code. Since I have the pseudocode, I could read it and translate it into javascript, java, python, or whatever other programming I wish to use. Pseudocode is also extremely beneficial when reading other people’s code on stackoverflow or whatever other website you’re using to help find out an answer to a programming challenge. Even if the stackoverflow post you are looking at has code written in a programming language you have no knowledge of, if they have pseudocode available to explain their code, then you can use the knowledge from the pseudocode to your own advantage! Pseudocode is pretty convenient.

Geese see god but goose apparently don’t

Sources