DEV Community

Cover image for Avoid Sleazy Code with Easy Pseudo Code

Posted on

Avoid Sleazy Code with Easy Pseudo Code

Ever wanted to code on your keyboard like Nikolai Rimsky-Korsakov playing his "Flight of the Bumblebee" on the piano? Do you wish your code flows like Tyler Joseph's rap verse on "Drown" from No Phun Intended? Do you wish to have a relationship with your computer comparable to Bonnie and Clyde? Do you ever feel like a plastic bag?

how you feel, when you're not using masterful pseudo code. Colorized circa 2019 before reading this blog post.

The stepping stone between man and machine; Pseudo Code bridges the gap between the way you think and the your computer understands. Writing with Pseudo Code, when done right, will help you create structured code with a defined path and direction, and stops you from feeling like a plastic bag (Drifting thought the wind, wanting to start again).
How to NOT write your Pseudo Code lines
Before getting into how to play the "The Devil Went down to Georgia" on your pseudo code fiddle, We're gonna talk about how to keep it well-Rosined to set yourself up for success. We wouldn't want you to lose your soul to the devil or anything like that.

The Pseudo-Code-Fiddle-playing-Devil, warming up as he waits for you (in Georgia)

The worst thing you can do is overdo your Pseudo Code. Pseudo Code should be direct, and simple, Just like good GPS navigation directions. Feel free to make it funny without making it harder to comprehend, just like installing Kevin Hart's voice pack for your Waze GPS here.

Left to right: Your very awesome and funny pseudo code riding shotgun, and you being equally awesome and funny. Colorized circa 2019 After you've read this blog post.

How to actually write your pseudo code lines
Let's say we're writing the code for you to pick a nice top to match your outfit in the morning. Your code should be short and simple enough for your to understand. You don't want to be deciphering your pseudo-code when you're already running late to your meeting and your company's "Business Casual" definition does not allow you to show up shirtless.
here is a bad example for this scenario:
//Open the door on the closet with your right hand, the dominant one that's located to the right side of your body which is also attached to your arm.
Do not write what you won't need. You're only explaining this to yourself, and maybe a few others that will read your code. your lines of pseudo code should look much mode like the following:
//Open closet
make sure to not over-simplify your code because that could take equally as long to decipher. Here is another bad example:
//pk st
Spell it out. it makes it easier to read.
//Pick shirt
Where to get your lines of pseudo code and how to structure them
Now that you know how to write your lines of code, Let's talk about how to derive them.
Each line of pseudo code should describe not less than one line (duh) and usually not more than a few. Occasionally your line of pseudo code will be describing a simple but long code block and that's okay, That's exactly what you want. Your pseudo code lines should only describe the current operation at hand. Instead of jumping around in the way kids do in a bouncy castle and being all over the place, your pseudo code should stay in the local scope of what its describing like an adult on a mini trampoline.

Your awesome pseudo code lines describing their own operations individually but in unison, then turning to horses because programming is magic and you're a wizard, harry.

Here is a bad example of the getting dressed in the morning conundrum, followed by fabulously structured pseudo code that won me the golden pseudo code fiddle.
//open closet to pick tops from inside.
//look at the tops that you're picking after you've opened the door
//realize that you own just 13 of the same plain tshirt because you're a programmer and you're about that life
//still show up late to the meeting. sorry. traffic was crazy
^ Bad example. a bit all over the place and too descriptive, but I hear the original writer has a good personality…

//Open closet
//Pick out all clothing that fits outfit as a top
//Subtract all tops that don't fit your mood today
//Pick your favorite top from the collection
//Return other tops to closet
//Close closet (don't wanna be taking up too much memory, we have to watch out for our brothers out there who use google chrome and only have 1.3 megabits of ram to spare when they have 2 tabs open.)
I hope that by the end of reading this that you've had a good laugh or two and got a new perspective on pseudo code. Remember to describe the current block of the solution using simple and clean terms, and don't be afraid to be a little funny sometimes. In the end, do what works for you, you'll find it as time comes. Hopefully the next time you're using pseudo code to tackle a hard problem it won't feel so much like playing 3D-chess against Neil deGrasse Tyson in space, but if it does I hope he lets you go first.

Top comments (0)