The Subtle Art of Pseudocode and Winging It
Split Logic and Syntax On a recent 1 to 1 call with Rafeh Qazi I discovered the importance of pseudocode for programmers. Coding isn't easy for any beginner so it would make sense that we would try and make the process as simple as possible for ourselves. This sounds highly rational, but our emotional mind often overpowers our rational mind. The emotional mind has a tendency to try and wing things even though the rational mind knows that this doesn't lead to consistency or any meaningful progress.
The Problem Set
I will paraphrase the problem set that Qazi gave me as follows:
Create a function that detects if a word ends with ing. If it does then change the word to it's infinitive, e.g. building would become to build. Otherwise return not a gerund
What Winging it Looks Like
If you were wondering, here is the end result:
As you can see from the above code, when I tried to wing it under time constraints my brain tried to remember everything I had learned so far and there was a mismatch of information. I knew how to iterate backwards over a string but I didn't know how to stop. For some reason the fact that the list counts backwards from -1 and not zero still doesn't come naturally to me. This is in spite of the fact that when I take a few minutes to think about it logically it makes sense to me again. When under a time constraint I also failed to recognoise that letter could only be equal to a single letter not three.
Pseudocode - Simplicity amidst Chaos
Thankfully there is an answer to this madness. Pseudocode splits logic and syntax so I can deal with one challenge at a time. It may surprise people outside the field of programming to hear that human logic is the hard part. Even as a beginner, I can see that the syntax begins to write itself once my brain comes to terms with it. The brain comes to terms with a new syntax from practice and repetition. My conviction behind this belief stems from language learning. Here is an example of the same problem with pseudocode. In Python you can write comments in your code by putting the # symbol before the text:
As you can see in the comments section in the above code, we broke the problem down into each of it's component parts. The simplest thing to begin with is to return the not a gerund statement. This means that any words that don't end with ing won't even make it past the not a gerund statement.
If however they do make it past this initial check, they will move onto the next stage, which is the else statement. As a beginner I still tend to get this logic backwards, perhaps because the wording of the problem still throws me off balance. The best way for me to remember the logic is to come up with an analogy. The subconscious mind thinks in pictures so I am far more likely to remember an analogy.
I imagine I am trying to get into an exclusive nightclub called the ING. There are 2 bouncers at the door checking ID's. This is an exclusive club and they want to stand out, so instead of checking for age they are checking to see if my last name ends in ing. If it doesn't they won't let me in. I decide to chance my arm but when I get to the door they turn me away because I am a Murphy. That's it night over before it even began! Some of my other friends get in and leave me outside, 'nice to know who your friends are' I think to myself. I then think 'screw them all, I will start my own nightclub and show them all!!'
Can you see the powerful emotions we create from stories and analogies? We don't tend to forget emotions as easily as logic.
The last part is the else statement. If the word has made it this far then the word does end with ing. So now we need to remove the letters ing? Well not exactly. Let's go back to the analogy for an explanation here.
Seeing as the person has made it into the nightclub because there surname ended with ing, it would be a little silly if we discarded the criteria they got in with. We want uniqueness in our nightclub but we don't want to take some of our clients identity away to get this. So, we decide they can keep their ing but as everyone else has ing in their surname we will just print their name badges up until the ing part.
Thankfully the 'to ' part is constant so we can now just concatenate the string with 'to ' + <string> . Concatenation is the term that is used to describe adding items together. It stems from the latin verb concatenare which means to link together. It is important to have the trailing space after 'to ' within the string so that you get the result 'to build' and not 'tobuild'
Did you find this blog post useful? Have you used analogies in the past to help you remember things? If so I would love to hear from you in the comments section below or by dropping me an e-mail.