DEV Community

Cover image for Moving Past Tutorials: Pseudocode

Moving Past Tutorials: Pseudocode

Ali Spittel on May 07, 2019

An often overlooked part of coding is pseudocode. Pseudocoding involves thinking about the steps to solving a problem and writing them in plain wor...
Collapse
 
laurieontech profile image
Laurie • Edited

Love all the different examples. And the reminder to consider edge cases. It's easier to write pseudo code for an algorithms problem than for an application, showing both is a great way to see how you get from here to there :)

Collapse
 
gypsydave5 profile image
David Wickes • Edited

Interesting! I think it's really important to learn how to get past the blank editor problem - there's nothing more intimidating than a blank sheet of paper. I've not tried doing it with pseudocode.

I rely on writing a test first - identifying one behaviour of the program I want to write and imagining that I've already written it. What does it look like? What will it do? What function gets called? With what? What will it return?

For me, a test gets me solving one small problem, gets something down on the page and stops me fretting about everything else that's going on in the code/in my life/ on TV.

Does your pseudocode have an afterlife? Does it be become comments or do you tend to bin it once it's been replaced by code?

Collapse
 
aspittel profile image
Ali Spittel

I think that's a really natural progression, and I normally write function declarations or tests first too. But, for beginners/jr devs, I think writing more traditional pseudocode is super helpful. It depends on the program, but I am normally minimalist on comments for simple code, maximalist on longer form documentation.

Collapse
 
horus_sky profile image
Cedric W

I really like this write up Ali. I’ve done pseudo coding without knowing it actually had a term πŸ˜‚. Mines is not as organized like your examples above, it’s more scatter brain but I try to outline what I may need to accomplish a task in bullet points or sentences.

Collapse
 
tamouse profile image
Tamara Temple

Interestingly, way back in the Jurassic of computing (1970s) we were taught to always begin with pseudo-code; this was primarily because the means of getting the computer read our programs was punch cards, but it still makes sense.

Collapse
 
jijii03 profile image
lincey.J

Pseudo code is the first thing I've learn when I started my software programming course in school it's so useful for later!

Collapse
 
jaakidup profile image
Jaaki • Edited

Nice, I've always loved writing pseudo code as a starting point for programs or functions, usually just a piece inside the comments section, which really serve as a focus and guideline for what needs to be done. (And proof that you know what to do :))

Maybe one day all code will be written in pseudo code...mmm

Collapse
 
nirwei3 profile image
nirwei

great article, couldn't agree more.
pseudocode is definitely a very important practice, a by-product of which are great comments in the code.
if you write a concise version of pseudocode inside the code and then add the relevant code beneath it, you've just got yourself comments that will help you (or anyone else) who will need to maintain this bit of code in the future

Collapse
 
falansari profile image
Ash

I remember once during my graduation project, which was for a real client, I got stuck on some security bug for two whole weeks! One day at the office as I was panicking about lost time and the looming deadline, I grabbed a notepad and pen and tried to think it through. Lo and behold in just 10 minutes, I found the logical issue by writing out pseudocode and rewriting it and going through the logic in detail.

Needless to say I learned my lesson the hard way. Since then the very first thing I do before I write any code is write out the logic of the program in comments as pseudocode, and more complicated things I start them off on paper.

If you're stuck, pick up a pen! You won't regret it.

Collapse
 
johnkazer profile image
John Kazer

Having started to properly learn functional programming I noticed that pseudo code leads very naturally to finished code. For example your initial reversed_string pseudo code is almost a classic form of recursion as it stands.

Collapse
 
xalxnder profile image
Xavier

This post is a game changer for me. Thanks Ali !

Collapse
 
tarialfaro profile image
Tari R. Alfaro

I love it! I write articles and focus on the problem solving part rather than a specific programming/scripting language.

Collapse
 
guin profile image
Angelika Jarosz

Such a great series!

Collapse
 
johnangel profile image
John Angel

Thanks for reminding us this basic but powerful concept!
Good bye blank text editor :-)

Collapse
 
pydorax profile image
Ibaakee Ledum

Thanks for this, always on point..

Collapse
 
murtezayesil profile image
Ali Murteza Yesil

I am never getting a dog

Collapse
 
qcgm1978 profile image
Youth

I think it's pragmatic for solving leetcode. I'd try it when I challenge them.