Programming as a Cure for Burnout

Just putting this here so I will see it next time I need it...

If I've been fighting with a bug, or a new technology that just isn't working for me, I eventually lose energy.

A solution that has worked for me is to find a way to write more working code, while still staying somewhat close to the problem.

For example:

  • Write "toy" code that uses the new tech I'm stuck on.
  • Write, and test, a wrapper for something I've partially learned which is still being troublesome in my project.
  • Review existing code and rewrite it with a cleaner design
  • Write more tests
The point is to write more working code, any way you can. Successful coding is fun and makes our brains happy. We get discouraged when we are not writing working code. So the trick is to find some place close to the problem where we can write working code, and write working code there until the whole thing is flowing again

Personal examples:

The previous incarnation of my study-project used jQuery, and used $.ajax(...) to talk to my REST service. And now I was learning React and removing jQuery. So I had to switch to fetch(...). And fetch+ES6+webpack was giving me cryptic errors and I was making zero progress over many days of lunch breaks. Not fun.

Steps to get unstuck were:
  1. Start a new, toy project with only ES6 and webpack, and a minimal node+express server
  2. Use fetch(...) to do a GET and a POST in the above
  3. Copy all the key bits of code for one successful fetch(...) into the main project
  4. Make fetch(...) do the simplest possible GET in the main project.
  5. Wrap the the code that does the GET in a wrapper function. And hang that function on the window object so I can play with it from the console
  6. Extend the wrapper function until it does all the things I will need
  7. Rewrite existing code to use the fetch wrapper
Making a general-purpose wrapper also pointed out some inconsistency on the server side. So now, for example, if the server returns anything at all, it will always be a legal JSON object. And that avoids other errors.

In fact, rewriting everything in the neighborhood to conform to a single consistent plan is a good general purpose tool for attacking mystery bugs. And even if it doesn't work, you still did some work that you probably needed to do anyway.



Comments

Popular posts from this blog

Callback, Promise, Observable, and Doughnuts

Learn grid and grid-template-areas FIRST!!!

The Day TDD Started Working for Me