Pseudocoding
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
Pseudocoding
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
- An informal high-level description
- Operating principle of a program and/or algorithm
- Uses of structural conventions of a programming language
- Intended for humans rather than machines
Pseudocoding
Explaining what your code does to a 3-year-old
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
What are the guidelines?
- Rule #1: No actual code allowed.
- Rule #2: Explain what you're doing in English using Software Engineering concepts.
- Rule #3: Each line must be something that can be turned into code.
- Rule #4: You don't need to know how that line will be turned into code yet.
- Rule #5: Indent pseudocode as you would real code to show control flow (loops, conditions).
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
Pseudocoding Course
- What's the point of pseudocoding?
- What are the guidelines of pseudocoding?
- When do we use pseudocoding?
- Examples of pseudocode
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
What's the point?
- Demystify complex problems
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
- Remove the need for you to hold everything in your head
- Create clarity and more definition to reduce ambiguity
- Give yourself a discrete, single solvable thing to work on - focus
- Explain your approach to someone else
Examples
Our task: add 5 to each item in an array.
//iterate through the array
for (var i = 0; i < arr.length; i++) {
//add 5 to each item
arr[i] += 5;
}
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
Pseudocode:
//iterate through the array
Pseudocode:
//iterate through the array
//add 5 to each item
Actual code:
You'll notice that each line of pseudocode gives us clear instructions for a task we can do
When do we use it?
- At the start of any problem we don't have an obvious solution to
- Whenever we get stuck
- In pair programming to explain our approach
- When approaching any complex problem
- In technical interviews, no matter what
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
All the time.
It's super valuable.
Be The Machine
- Practice "executing" your pseudocode with pretend inputs.
- Just as we like stepping through our actual code line by line to explain what it's doing, we can do the same with our pseudocode.
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
Be the Machine
create a function that multiplies every even number in an input array by 10 and returns the modified array
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
//declare a function that takes an array as a parameter
//iterate through that array
//check to see if each item is even
//if so, overwrite the array at that position with that item multiplied by 10
//return the array
"invoke" this with the array [1,2,3,4]
(all in your head, or before coding)
This helps you spot bugs before you even write code!
Key Takeaways
- Make your life easier. Before jumping into writing code...
- break down complex problems
- write down your step-by-step plan
- Follow the 5 guidelines
- Practice being the JS interpreter and mentally execute your pseudocode with pretend inputs
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
Today's Exercises
These exercises are not necessarily tied to today's lecture material (though you should always use pseudocoding to solve problems!)
![](https://s3.amazonaws.com/media-p.slid.es/uploads/362520/images/1635394/stucked.png)
Practice going through your previous repos/assessments (especially ones you found difficult) and try pseudocoding your way through them.
Pseudocode
By telegraphprep
Pseudocode
- 1,471