DEV Community

Cover image for How To Write Pseudo-code

How To Write Pseudo-code

Milecia on April 25, 2019

Have you ever had a really complex programming issue? An issue where you can probably write out the logic, but you aren't quite sure of the syntax ...
Collapse
 
keptoman profile image
mlaj

I usually write pseudo code first, then I code around it. The pseudo code becomes basic comments for my actual code.

I also make a simplified version with checkboxes that I put on our task manager for my superiors to see. They can then understand where I'm going with this task.

Great article !

Collapse
 
shahlan profile image
s.shahlan

Can share some example?

Collapse
 
crashley1992 profile image
crashley1992

I love reading your posts. I'm newer to programming and I appreciate how you cover a lot of things that aren't brought up in tutorials. I think pseudo-code is something I need to get in the habit of doing more. Especially if I step away from a project for awhile and come back to it.

Collapse
 
m0veax profile image
Patrick Kilter

As mentioned in another comment, I write my pseudo code as comments in my script / program and fill it in Afterwards.

So you know what you thought at this moment even a few years later.

And another people will understand what you did too :)

Collapse
 
flippedcoding profile image
Milecia

Thanks! I'm glad my posts are actually useful! 😊

Collapse
 
nelo_mf profile image
Manuel Fernandez • Edited

I've been coding for about a year and a half, and today I bumped into a really complex task at work, which involved (as usual) reading another coworker's code. Luckily, I had read this post on my lunch time, and it really helped me to better understand the existing codebase (since I was able to grasp the logic behind the problem by using pseudo code). Thank you for sharing!

Collapse
 
afairlie profile image
Ariane

I'm just new to coding and I love this approach. Thank you for this post!

Collapse
 
flippedcoding profile image
Milecia

Thank you! I'm glad it's helpful.

Collapse
 
afairlie profile image
Ariane

I also think the academic pseudo-code is interesting

Collapse
 
markaurit profile image
MarkAurit

Pseudo-code is a great tool for working with large code bases that you didnt write in the first place, especially if they are complex. Or your own, 6 months later after you've moved on! As a senior I'll often tell younger devs to pseudo-code a task and bring it back to me before writing code; if their pseudo-code is correct I know they understand the problem and have much higher confidence they will write correct code.

Collapse
 
fpuffer profile image
Frank Puffer • Edited

Yeah, but why not let them write real code and do a code review soon. It might cause a bit more work for you but it is safer and the junior will probably learn more. Coding is not like building a house. Code can easily be modified. Version management tools exist. Refactoring exists.

Collapse
 
andrei_says profile image
Andrei Andreev

Different level of abstraction which allows for ultra efficient communication and review of logic.

Collapse
 
fpuffer profile image
Frank Puffer • Edited

I completely disagree.

Pseudocode might have made sense in the age of assembler, FORTRAN and C programming but nowadays the two main reasons for using it are probably:

  1. Not mastering your programming language.

  2. Not knowing about refactoring - nobody gets a non trivial task right at the first try. Code is not something you write once and never change it afterwards. But that's not a bad thing: Changing code is cheap if the code is clean.

Maybe there are some rare occasions where pseudocode does make sense but in most cases there are better tools to use when you are not yet ready to code: Draw diagrams write specification documents, talk to people, build a prototype, write unit tests (TDD).

What sucks most about pseudocode is that it will not provide any feedback.

Why does this matter to me after all? Because I think that it is much more helpful in the long run to put your energy into the real code.

Collapse
 
kerushag profile image
KerushaG

Hi, nice article but I'm a beginner and I know I should nail this habit in now. I'm doing a bootcamp and the exercises are getting a bit more challenging, when I try to write pseudo code, I get trapped by 2 things. 1) I come from a more academic background, lots of essay writing, and so my pseudo code never comes out in simple digestible chunks and 2) sometimes I am not even sure how I will need to do what I need to do and so I end up just jumping right in and playing around, I never go back to writing pseudo code and if I made any attempts if offers me no guidance, because I'm like learning on the go about what works and doesn't. Any advice on how to improve on this?

Collapse
 
codelitically_incorrect profile image
codelitically_incorrect • Edited

Why did you bother posting academic pseudo code? It ruins the opportunity to share the article to someone who is learning

Collapse
 
flippedcoding profile image
Milecia • Edited

It's just there as another example of what pseudo-code can look like and just how complex it can be if you need it. 🙂

Collapse
 
erclairebaer profile image
Claire McCrea

I see both sides here.

I appreciate seeing the more complex side, but complex pseudo-code isn’t the focus of the article, and presenting it as the first example makes the reader think the complex stuff is what pseudo-code -really- is— and that the simpler example is just “dumbed down”.

Maybe it would help if the examples were used in a different way? Like, “pseudo-code can be simple [example] or complex [example], but it’s overall goal is to...”

Thanks for the article! It answered a few questions I had 😊

Collapse
 
yriiarutiunian profile image
yriiarutiunian

I can barely remember the last time I had to write pseudo-code. Usually I did, when I had to write something really difficult to just imagine in my mind. Nowadays, the stuff I code are pretty simple

Collapse
 
eddisonhaydenle profile image
EDDISON HAYDEN LEWIS

Yes, Pseudo-codes are exactly necessary initially as it would allow the team(s) to brainstorm broadly as opposed to jumping straight into code.....

Collapse
 
rnrnshn profile image
Olimpio • Edited

Love it. Clearly is the best way to approach an algorithmic problem

Collapse
 
fpuffer profile image
Frank Puffer

What makes you think so? Does real code really suck that much? If yes, shouldn't we better find out why that is so and try to do something against it?

Collapse
 
d_uck_504fc6ea80bae3084 profile image
D U C K • Edited

I am a student learning pseudocode in my computer class, this article really helped!! :)