DEV Community

Discussion on: Explain Pseudocode

Collapse
 
dmerand profile image
Donald Merand • Edited

To me, pseudocode is nice when you need to understand the algorithm you're using without getting stuck with language implementation details. In your Python examples above, you approach the algorithm in a certain way because you are secretly thinking "I need to make sure to declare my variables and use a specific looping syntax, etc." Pseudocode allows you to forget about all that and focus on the bigger picture. So you might start with:

# What is the algorithm actually doing?
until user_cancels_program
  print coin_flip_result

...and then worry more about implementation details like "How do I flip a coin?"

coin_flip_result = a_random_boolean

# Or, more explicitly;
coin_flip_result =
  let flip = get_a_random_boolean
  heads if flip is true
  tails if flip is false

You can just pretend that you're using a magic programming language that takes care of things for you! It's pretty nice, and you can easily convert that to Python or JavaScript or what-have-you, once you figure out how you want things to generally work.