Approaches To Problem Solving
"In programming, the hard part isn't solving problems, but deciding what problems to solve."
- Paul Graham, Problem Solving.
Quotes
"Programs must be written for people to read, and only incidentally for machines to execute." – Abelson & Sussman, SICP, preface to the first edition
“It may be desirable to explain, that by the word operation, we mean any process which alters the mutual relation of two or more things, be this relation of what kind it may. This is the most general definition and would include all subjects in the universe.” - Ada Lovelace.
"That language is an instrument of human reason, and not merely a medium for the expression of thought, is a truth generally admitted." – George Boole, quoted in Iverson's Turing Award Lecture
The sons of Hermes love to play,
And only do their best when they
Are told they oughtn't;
Apollo's children never shrink
From boring jobs but have to think
Their work important.
– W. H. Auden, Under Which Lyre
Tell your non-tech friend a story about a time you:
- Got blocked on a simple problem
- Solved a problem in an elegant way.
In both cases:
- What was the problem?
- What problem solving techniques did you use?
- Here is a link to my replit page: Manipulating JS Objects
- Please click here for my answers - This link leads to my Notion Notes on Manipulating JS Objects
- Got blocked on a simple problem
- The ** operator is not supported on this platform
- You could accomplish this by using a while loop or a for loop, but please use a for...of loop!
- Solved a problem in an elegant way.
- I got help and then understood how this solution works.
- What was the problem?
- My problem is that I'm half-way through a JS course online, so I do have some basic understandings of JS, yet it's not a Big Picture understanding. I am missing some fundamental key blocks of knowledge, which makes problem solving that much harder under the imposed time constraints.
- What I've been doing: alternating between the Katas on this course and continuing to progress through the JS course I'd taken before starting this bootcamp, so as not to confuse myself. I know once I've finished this JS course, I will feel better.
- Thus, the problem is trying to solve problems without a strong enough foundation - and accepting and navigating that as best as I can, anyway.
- What problem solving techniques did you use?
- Continue with the course, talk to peers.
- Here is a link to my replit page: Manipulating JS Objects
- Please click here for my answers - This link leads to my Notion Notes on Manipulating JS Objects
- How did you feel throughout the process?
- Frustrated and persistent anyway, despite feeling emotional at times.
- What did you learn?
- Breaks are not a luxury, they are necessary and often help with problem-solving.
- Pseudocode ☑️
- The rubber ducky method ☑️
-
Reading error messages ☑️
-
Console.logging ☑️
- Googling ☑️
- Trying something ☑️
- Asking your peers for help ☑️
- Asking coaches for help ☑️
- Improving your process with reflection ☑️
-
Many of the techniques mentioned above can be applied to all sorts of (non-technical) problems, but pseudocode is coding-specific and incredibly useful to help you think through your code.
Pseudocode is not actual code. Rather, pseudocode is composed of comments that tell you how the code will eventually look.
It is informal, plainly written steps that form the rough draft or outline of your code.
Pseudocoding involves taking a little time before you get into writing the code to break down your plan into small steps. This means you don't have to worry about making the whole thing work at once, but can instead focus on just coding one step at a time. This can be useful for helping you break down a complicated problem, but can also be used if one developer needs to leave instructions for another to complete the code later.
Because pseudocode is the steps rather than the code itself, you don't need to include the fine details of what needs to happen. It's a bit like recalling a recipe you know, you don't need all the details immediately, you just need to know the ingredients needed and can work the rest out when you get to it. For example, to make brownies:
// put butter, sugar, and cocoa in bowl and then microwave // add eggs and vanilla and mix through // add flour and mix until thick // bake!
You can see that we didn't include any details, just general steps.
Once you have written pseudocode, you may find you need to change the order of steps, or you might discover that you have forgotten some and need to add them in - and that's okay! This is only a first draft and it will inevitably change as you come to write the code itself.
- The name is in reference to the book The Pragmatic Programmer where a programmer would debug code by explaining it, word by word, to his rubber duck.
- "I don't have a rubber duck, but I'll start explaining the code to my wife, who has no idea what I'm talking about, and eventually figure it out. I call it using my sounding board to bounce ideas off."
- "In general, explaining something to someone else is a good way to improve your own understanding of it. It forces you to think about the parts that you don't really understand, pointing out the gaps in your knowledge or reasoning."
test
Tell your non-tech friend a story about a time you:
Here is an example of a problem I was trying to solve a problem using a For...Of loop:
Please use a for...of loop to loop over an array and print out the square of each value (the number multiplied by itself).
NOTES:
const numbers = [1,2,3,4,5,6,7,8,9]; //DON'T CHANGE THIS LINE PLEASE! // WRITE YOUR LOOP BELOW THIS LINE: for ( let number of numbers ){ console.log(number * number); }
Originally, I wanted to write it like this:
for(let squaredNums of numbers){ console.log(Math.pow(numbers)); }
Since the variable already existing was called 'numbers', then (in terms of singular and plurals) it makes sense to call it number of numbers. Also don't need to use the Math.() method when you are just squaring (multiplying) a number by itself. Try to keep it simple.
In this example, I think I would have to consider what defines 'elegant' code.
Elegant code uses cleverness to accomplish something in much less code than most people would think possible, but in a way that's readable and obvious in hindsight and doesn't look like code golf.
According to this definition, I would say that the number * number solution is much more elegant than applying the Math.pow method, just because the first solution is more intuitive and appears to be simpler.
In both cases:
Reflect on how confident you feel using the problem-solving techniques and process:
Pseudocode (From Dev Academy)
Another simplified definition of Pseudocode:
Pseudocode is just any representation of code that isn't actually code (the pseudo prefix makes words like that)
So for example, while I might say the following in code...
for(let i = 0; i < 10; i++) { console.log(i); }
We could also express it in more human-readable pseudocode...
loop from 0 to 10 print loop index
There is no specific syntax for pseudocode, it literally can be anything you want.
The rubber ducky method
Reading error messages
JavaScript error messages && debugging