Karen Nelson

Karen still wrestles regularly with JavaScript and is finding that her victories are coming more easily. She’s chronicling her career transition from elementary school teacher to web developer on KarenJNelson.com. She also continues to navigate the less predictable world of education as an assistant preschool teacher. She shares advice for other teachers who want to use technology in their classrooms on her website, Technology In Early Childhood. Karen lives in the Pacific Northwest with her husband and two children. You can also find her on twitter: @MrsNelsonCWA.

Published Thoughts

Why I Love Broken Code

I got stuck with a project yesterday. Really stuck. I was stuck all day long. I’d built a website in honor of my daughter’s Harry Potter themed birthday party. The website had two purposes: 1. To share pictures with friends and family. 2. To practice my code skills.

I’m a brand new web developer. I took my first programming class (Ruby) five months ago, wrote my first line of HTML two months ago and my first line of JQuery about a month ago. Everything is still very new to me. I’ve been feeling like I needed a deeper understanding of CSS and this seemed like a fun way to get it. So I opened up my text editor (which still feels very fancy and technical) and began putting in some HTML. Then I added some CSS and started to code a little pop-up modal just for fun. I wanted to get a sense for how it was starting to look. So I copied everything into JSBin and it looked fabulous. I decided to add a little more JQuery to finish up my pop-up modal, to spice it up a little. I also added some expandable sections on the page. My JQuery pieces came together like they never have before. My code ran correctly the first time, which I was not expecting at all. Usually I have at least one typo, if not a coding error or two.

Feeling pretty good that I could whip up an interactive site in just a couple of hours, I began to copy my code from JSBin into the appropriate files in my text editor, ran my FTP program and put the site up on an empty domain I’d bought a year ago for a blog idea I’d had that had never become reality. I watched the colors and text all fall into place, and I clicked the modal. I watched the window pop up. Then I clicked the ‘x’ that was supposed to close the modal and nothing happened. None of the rest of my JavaScript was working. Only the first function was working. It had worked perfectly in JSBin and now, it was broken!

This had happened to me once before: everything worked great on JSBin, but then the JavaScript wouldn’t work when I put the site up live. That time the problem had been that I’d had the link to the JQuery library after my own JS file, so when the browser ran the code, it didn’t know what to do with the JQuery I’d written because it hadn’t been introduced to the library yet. (I was stuck on that one all day too!) So this time, I’d made certain that all of my JS links were lined up properly. I’d carefully traced the file path to make sure that my link to my JS went to the right file. And yet once again, my code would run in JSBin (and JSFiddle!) but not live. (Can all of you experienced developers out there guess the issue? I’m curious. Read on to see if you guess right.)

So I turned to Google. All day long I poured over articles, Stackoverflow posts, the JSBin help section and even coding forums I’d never seen before. I’d walk away for awhile or work on my current Ruby project and then I’d come back for another look at my JS dilemma. I ran both my HTML and my CSS through the validator. I found and fixed a couple of HTML errors but my CSS was perfect (for the first time ever!). I added and removed various lines of code, trying to see if a plugin here or there was causing errors. None of those changes made a difference. I’d reached out to a few people online that I thought might be able to help, but hours had passed and I was no further in fixing my broken code. I was absolutely, solidly, stuck.

Then I remembered an article about JavaScript Debugging for Beginners that I’d come across a few weeks ago. I’d saved it because while most of it was over my head at the time, I knew it would be useful in the near future. I was right. I started reading through the solutions and found the advice to open up the developer tools and look at the console. Why hadn’t I thought of that?? I started to click around in the console, and that’s when I found it: it showed the JavaScript that it was running, but it wasn’t the Javascript that I’d been using in JSBin or JSFiddle. It was the very first JS I’d written before I’d started working in JSBin. Somehow, I’d ended up with two. js files and my current code was not in the file that I had so carefully linked to! I quickly copy/pasted the right code to the right file, FTP’d it to my domain and it worked! Everything worked, just like it’d been working in JSBin all day long!

And that’s the first thing I love about broken code: That extroidinary feeling of accomplishment I have when I finally fix the broken piece. It’s such a satisfying feeling. There were so many times over the course of the day when I wished that I could just call up some JavaScript expert and have them tell me how to fix it, but then I would have missed out on my first favorite thing about broken code: a sense of accomplishment. I love knowing that I fixed it, and that if I fixed it once, there’s a good chance I can fix it again more quickly the next time I make a similar mistake.

The second thing I love about broken code is that even when it’s entirely broken, I can know with confidence that there is a way to make it work. There is a “right answer.” If I work hard enough, it can be figured out. That’s something that just hasn’t really existed in my last two professions as mom and teacher. There is no one right way to parent a child that we can know with certainty will produce a desired result. There is also not a single right way to teach every child that will result in the same outcome each and every time. In contrast, I really appreciate the black and white nature of writing code. Either your code works or it doesn’t. And if it doesn’t work you can fix it so it does, provided you’re stubborn persistent enough, which I am.

Finally, the last thing I love about broken code is the freedom to fail. There’s almost an expectation of failure when you’re writing code. True, in the end your code needs to work well, but it’s highly unlikely that anyone’s code is perfect the first time they write it. Otherwise there wouldn’t be such a plethora of websites and articles devoted to debugging code. Code is buggy. Whether it’s because you have a real life moth in your mainframe, or have a missing semi-colon, it’s rare for code to start out perfect. The realization that virtually no one starts out perfect takes the pressure off and frees me to be more creative and relaxed when I am building with code.

I’m having fun writing code. I think Web Development is a particularly fun place to build because you can almost instantly see a physical representation of your efforts. It makes the abstract logic of programming much more concrete. So even though I know I can expect lots of broken code in the future, I’m still excited about programming. I’m excited because I know that even when my code is broken, I will be able to fix it, and that sense of accomplishment is empowering and motivating. It’s what keeps me going.