Like A Girl

Pushing the conversation on gender equality.

Code Like A Girl

Why I’m glad I failed my code challenge

So, there I was. I had completed most of the deliverables for this module’s test (“exam” sounds too formal, “code challenge” sounds too fun). It was writing out the missing parts of a multi-model MVC structure and being able to navigate interlinked show, index and new pages in the browser: only half a CRUD, all things considered.

But…. I’d hit a bug.

A NoMethodError, to be precise. It was telling me it couldn’t run the collection_select on the @powers array because…. there was nothing in the powers array (collection_select maps onto a group of things and magically makes them into a drop-down list). Huh? But I’d already set @powers in the PowersController? IT’S ACCESSIBLE. PLS. Y U DO THIS.

There’s nothing like being under time constraints to really bring out the stressed pragmatist in you. So, I started debugging. First stop was Byebug — similar to Pry, it’s a tool which halts the program when it hits the keyword, so you can effectively stop a program right in the middle of a method, if that’s where you’ve decided to plop the word byebug.

Caveat: I tell a lie. First stop was actually heaving a big, silent sigh and doing this to myself:

I’m sorry, inner Mace Windu

But then I was like…. hey. It’s okay. Mace Windu isn’t going to fix these bugs. Shut up, inner Mace Windu. I’m busy.

A bit of fiddling demonstrated I could isolate the error by removing line 6 — and the page rendered fine. Stupidly, I read the error but decided maybe I could crack it without paying attention (I’m sorry I’m actually cringing just writing that WHY DID I NOT JUST READ THE ERROR). Maybe it’s the arguments I’m passing in to the collection_select? I thought. Stranger things have happened. I’m still getting to grips with what to pass in — so playing it fast and loose with a lot of added YOLO means if something doesn’t work, I’ll try a slightly different permutation. However, this doth not a decent problemsolver make, so I thought maybe I should just be reasonable and read the documentation again.

thanks for nothing, API Dock!

Yeah….. nah. My arguments were, as far as I could tell, fine. I even , in my desperation, checked code from a lecture because I was so certain I was passing things in right but felt undermined by the error. You’re not really supposed to do this, but I have my reasons*. It was left field but I’ll stand by it. I’m here to learn, not just to pass tests, and I’m hunting understanding, not grades, but I STUPIDLY wasn’t using the resources available to me (test-driven development and test feedback on something quite simple which totally stumped me). So that’s a learning point right there. Always learn from code that’s better than yours, right?

My byebug, however, revealed what I had originally thought. @powers was nil. Despite being assigned in the Controller.

Ah… wait a second. I’m trying to render the new page. Not the create page. Why have I put create in there? new will create a GET request for rendering a blank form for a new instance of the model; create will pass in params for a new instance as aPOST request, persisting it to the database. I don’t even HAVE a create page.

Unfortunately, though, I’d run out of time.

I rushed out of the room immediately to ask an instructor what was going on. He helped me notice the error. UGH, I’m such a bozo.

the working code

Et voila!

the working form

Painful. But… I’m proud that I did 90% of the task very smoothly, and understood what I was doing, rather than just regurgitating code or pattern-matching. I’d happily do it again (which I do have to do, because I failed, because obviously my form didn’t work when I handed it in). I also got useful feedback on how I style and indent my code, and got to ask questions. I don’t mind failing at something if you get another crack at it, and the amount of personalised support you receive here is stupendous.

What I’ve learnt from this (ordeal?) experience:

  • my typing is terrible, but that seems to be okay for developers (woo!)
  • Mace Windu-ing myself doesn’t really serve a purpose, it just kind of winds me up
  • * if these challenges are graded templates for technical interviews, here is when I would have turned round and asked for clarification, help, a hint, or explained my thought process. Developers don’t work in isolation, and I don’t mind asking for help
  • I did a thing!