The When, Why, & Where Of Pseudocoding. How to bring logical thinking into your coding.
Tags: pseudocode, javascript, problemsolving
Published: 2023-08-14 15:21:33


## Overview of Pseudocoding
Pseudocoding is an essential skill in the world of programming that often flies under the radar. It's a method of problem solving simular to that of building a blueprint of floor plans of your house before bringing in the materials in building. Pseudocoding helps you put your prospective code into a light that may help you understand it better. 

## How Pseudocoding Affects Me
One issue I historically struggle with is tests, live ones at that. I get nervous, think about the time remaining and the consequences of not passing rather than the code itself. And that may be some undiagnosed ADHD talking but thats not a good excuse for poor planning. I was recently faced with a pass or fail program type of test and the one thing that helped me the most? Talking through the problem! My past issue was that I just jumped into the code and relied more on just hoping to know the code to write, which is why utilizing the powerful tool of pseudocoding and talking out loud is so valuable. It let's you understand the 'why' of what you're doing, and also figure out how your code should look before writing, that way you don't get blindsided by errors that stunt you early on. Below I will go through a few key topics; Why to pseudocode, When to pseudocode, Where to pseudocode, & finally how to translate that into real functioning and effective code.

## What Does It Look Like
Psuedocoding can honestly look however you'd like it to work, as long as it's effective for you. But typically it looks like commented out code, that has a simular structure to a normal function or code, but is more descriptive and explanatory to what each line does, see below for an example:

```javascript
function cash register (money amount we received from user) {
const change = money given minus price of item selected
if (change is a positive number) {
   return change amount and say 'have a nice day!'
   }
   else if (change is negative) {
      return amount still owed, and say 'you owe ${change} 
       still`
      };
else if (change is zero) { 
      return 'you are all set!'
      };
else (change is NAN) {
     return 'incorrect form of payment, please try again'
      };
}

```


## Understanding the Purpose of Pseudocoding - (WHY)

Pseudocoding serves as a bridge between the abstract world of problem-solving and the concrete realm of coding. It involves crafting a high-level description of the logic and steps required to solve a specific problem without getting bogged down by the complexities of a particular programming language.

## Knowing When to Use Pseudocode - (WHEN)

Pseudocode is particularly useful during the initial stages of problem-solving. It allows you to outline your approach, break down complex problems into manageable steps, and get a clearer grasp of the overall logic. Pseudocoding is not meant to be a replacement for coding itself, but rather a preparatory step that saves you from stumbling through the coding process without a clear plan.

## Where Should Your Pseudocode Go? - (WHERE)

Now overall this comes down to a matter of preference for the most part, but it's always good to have a system of efficiency. If you have the time, and the neat handwriting skills, than hand writing your pseudocoding with pen and paper is a great way to go, otherwise writing commented out code underneath your functions is also a very viable choice. A large part of coding and also making it readable and in a good flow / order of operations, so keep that in mind when writing your pseudocode, You don't want to make a paragraph of pseudocode that stretches all over your file.

## Why Pseudocode Matters

1. **Clarity:** Pseudocoding helps you crystalize your thoughts and ensure you've considered all aspects of a problem before diving into actual coding.

2. **Less Language-Dependent:** Pseudocode is language-agnostic, meaning you can focus on the logic rather than the syntax of a specific programming language.

3. **Error Minimization:** By ironing out the logic beforehand, you reduce the chances of making unnecessary mistakes when writing the actual code.


## The Best Time and Approach to Pseudocoding

The most suitable time to engage in pseudocoding is immediately after understanding the problem statement. Follow these steps for an effective pseudocoding process:

1. **Analyze the Problem:** Understand the problem thoroughly before attempting to pseudocode. Identify inputs, outputs, constraints, and the main steps required.

2. **Outline the Logic:** Break down the problem into smaller steps. Use simple, clear language to describe the processes involved without getting bogged down in specifics.

3. **Use Structured Constructs:** Utilize common programming constructs such as loops, conditionals, and functions in your pseudocode to better mimic the structure of actual code.


## Translating Pseudocode into Real Code

Translating pseudocode into actual code is a relatively straightforward process. Follow these guidelines:


1. **Turn Blueprint Into Building:** When writing your pseudocode you should typically write it in the form of what your actual code should look like, so when you're ready try to copy that into actual code, making changes as needed, then testing to see if theres anything you've left out.

2. **Focus on Syntax:** Pay attention to syntax details and conventions specific to the chosen language.

3. **Test and Refine:** Execute your code and debug as needed. The pseudocode serves as a guideline, but adjustments may be necessary based on the intricacies of the language.

In conclusion, pseudocoding might not be the most glamorous aspect of programming, but its impact on your coding journey cannot be understated. By providing a clear roadmap for solving problems and mitigating errors, pseudocode paves the way for efficient and effective coding. So, next time you're faced with a coding challenge, take a moment to pseudocode—it could be the difference between smooth sailing and a bumpy coding ride.

### Sources:
[Dev Ops Complete Pseudocode Tutorial](https://www.devopsschool.com/blog/complete-tutorial-for-pseudocode/) 

[Wikipedia source from MDN Web Docs]
(https://en.wikipedia.org/wiki/Pseudocode)