SO MANY POSTS TODAY!! I am playing a big ol’ game of catch up trying to document my learning journey.. so bear with me as I post my face off!!
In the last post I finally got to share a bit of my process for problem solving when I get stuck. I think that this topic deserves at least one post to itself.
Since starting to learn software, at Carleton University in 2013, I have been learning things that are really new to me. I graduated high school with lack luster grades and a very firm “Math and Science are the worst” attitude. Yuck, I know!! So when, on a complete whim, I enrolled in a Computer Science for the Arts course and to my complete and utter shock loved the heck out of it – I was immediately in over my head. Luckily I had a really great prof and a super supportive partner (who happens to be a software devloper.. yes that may have contributed to me taking the class.. but not to loving it – that’s ALL me!) who helped me get through the initial struggle. I still remember the thrill of writing my first bit of script, something like a simple math function. It. Blew. My. Mind. Not just because it was so cool, but because I was shocked at how clueless I was about technology and it’s inner workings.
As I learned I ran into so many problems. I have dyslexia and that means I mix text up sometimes – leading to many small typos with big consequences. Then there were all the standard problems people run into when learning software – that often stem from a limited understanding.
But when you screw code up usually it throws errors.. and when you google errors you find a world of answers, explanations and similar issues. So it’s relatively easy to learn software and gain insight from mistakes along the way.
Here are my steps to solving a problem. They might be a little more extreme than most but I promise they work!!
1. Read and Try to Understand the Error Message (if there is one)
This seems super obvious, but sometimes we avoid the obvious. So read it, think about it and read it again.
TypeError: Cannot read property 'push' of undefined at /home/ubuntu/workspace/yelpCamp/v2/seeds.js:44:48
First thing – TypeError – What’s a type? What does that mean? Does this help me connect the dots on finding the issue?
It means that a value isn’t the type that’s expected. Ok, that’s a little helpful but I need more details.
Cannot read property ‘push’ of undefinded
Ohh!! I pushed something! I remember that – now I have an idea of where the problem is in my code.
Then the sweetest hint of all: at /home/ubuntu/workspace/yelpCamp/v2/seeds.js:44:48
This tells me exactly where to find the problem, down to the file and line of code.
Now I have an vague idea of what kind of issue I’m running into, what part of the code is breaking and where it is breaking. I’m an amazing detective!
2. Scour the Code
This step is easy but tedious and so, so important. Find the area where it’s breaking and jot down all the pieces that connect there. Read everything closely, look for typos, inconsistencies and make sure it all looks good.
Keep in mind that this could easily become overwhelming on larger projects, which is why version control is so important. You need to be able to have a solid idea of when your code was last working as expected so that you can isolate the problem. Work in small steps, checking constantly!
3. Print EVERYTHING
If you have a TypeError a great thing to do is check the type of all the items around the problem. Make sure things are what you expect them to be and that your code is doing what you want. This is a really helpful thing to do as you work, it’s good to get in the habit of doing small checks along the way!
4. Ask the Internet
Google, read through stack overflow issues and maybe even ask the question yourself (if you’re sure it’s not already been asked and answered – which it probably has). I can’t over emphasize the value of the online community and product documentation. There is so much information out there and so much enthusiasm to share! I find myself on stack overflow daily, learning from other peoples experiences, learning a whole bunch about best practices and hoping to find questions I might be able to answer (I’m not quite there yet but this is the first step!).
5. Ask the Issue Aloud
This is a bit of a funny one! Often when I would get stuck on a problem I would walk over to my partner to ask for help. While trying to fully explain the issue, with proper context, 7/10 times I would solve it myself. It takes a decent amount of understanding to explain a problem (yes, this is why I am blogging now) so as you put the problem into words often it all makes sense. This happens so often that I have started to ask my dogs for help before resorting to a human and sure enough it works!
6. Walk Away
The most frustrating problems seem to manifest toward the end of my day, or after a long stretch of working on a project. This is not a coinicidence, my brain gets fuzzy and stubborn if I work too long on one thing. Often we have the solution, but we’re too stuck in a pattern to be able to see it. If we walk away, grab a snack, work on something else, go to bed or anything that gets our mind away from that tricky problem, our subconsious will chip away at it. Honest to Betsy, I have left my computer so frustrated, sure that the problem is impossible and I have no future as a developer, only to come back in the morning and have the solution be so obvious I don’t even have to think about it. No joke, this happens all the time. A great book that talks about this phenomenon and other amazing tricks for learning, remembering and problem solving is A Mind for Numbers By Barbara Oakley. She also offers a course, Learning How to Learn: Powerful mental tools to help you master tough subjects. I found both extremely helpful when I took up programming and high school math (10 years after doing any math at all).
PS. I loved math as an adult. So you youngsters out there who think that you can’t succeed at math listen up – YOU CAN! I promise! This is coming from someone who graduated high school with a 52 in math and TEN YEARS LATER managed to get above 80 in both grade 11 and 12 advanced functions. You can do it!! Heck I’ll help you do it – reach out for advice any time!
Alright, back to the topic of this post!!
These are my go to problem solving steps for programming. There are certainly many different ways to do it and I’m sure they will change as I learn more but they have gotten me this far. I hope they can help you as well! Most importantly don’t give up! You can do it, it just takes a little time and effort. You won’t ever stop learning if you decided to pursue software, there’s just so much out there that’s constantly evolving. I think that’s part of the magic for me – No one can be an expert at everything software. So no matter when you start you can gain a unique knowledge base and make meaningful contributions to a team of seasoned developers.. and of course you will always have to solve problems!