November 12, 2017
Getting stuck is part of life. It’s also part of programming.
As a fairly novice coder, I find the primary reason I get stuck is because of a pesky syntax error. Somewhere I forgot to put a parenthesis, or I forget to properly close a code block. It’s easy to miss these things, and the interpreter is unforgiving.
There are a couple of tools and techniques that I find help when I get really stuck.
- Carefully read the specs. At Flatiron, many of our labs are coupled with a set of specifications utilizing the RSpec tool set. RSpec tells you exactly what it expects and what you need to do to satisfy it’s requirements. Reading the out from RSpec carefully so that I understand exactly what is wanted is a good first step.
- Examine code character by character. Syntax errors stop execution of code before RSpec executes its tests. Usually an error message will tell you the line number that is presenting the problem, but sometimes the actual error is elsewhere. When I can’t figure out where my syntax error is, I slow down….way down… and examine my code line by line. And even then, sometimes it’s not enough. I have to examine my code character by character to make sure each and every token is exactly what I want.
- Find examples and compare. Sometimes I’m just way off. If I’m not sure how my code should be structured or I’m not sure how to use a certain method or library, I sneak online and look for examples or documentation. The online world is amazingly full of helpful stuff - so searching online is usually quite helpful. I also have a handy little app on my Mac that I highly recommend. Dash for MacOS downloads online documentation to your local storage and allows you to easily search for whatever you are looking for. It even has an iOS companion app that will display your search results on your iOS device. I open up my iPad next to my keyboard and search for help all the time now. The Mac app will download almost any open source documentation you can think of - including libraries and tools like Vim and Sass. And it updates the content for you from time to time so you have correct and current info.
These tricks help me move beyond a stuck point. But you know what helps when I’m really stuck? I step away from the desk and take a nice long walk, watch some TV, or (don’t tell) play a video game. Taking a break and doing something unrelated really helps. When I return to the desk, I usually find the problem much more quickly than I would have otherwise, thanks to having a refreshed perspective.