Wednesday, May 7, 2014

Taking A Break

No, it's not what you think! :D

Some time ago (January 2012, to be more precise), I started working on the very first problem on Project Euler. It was a lot of fun and I felt like I was playing a game. I finished the first problem, read the next and then abandoned Project Euler for lack of time. But I kept thinking about it.

And then I read Aja Hammerly's slides from last night's Seattle Ruby Brigade monthly meeting. Seattle.rb is having a programming contest to see who can complete the most Project Euler problems in the month of May. You can see where this is headed...

I signed up. So much time had passed since the last time I signed on to the PE site that I had to ask for the little username reminder email. Immediately after I crtl-v'd Aja's friend code into the little box I regretted it. How on earth would I find the time to work on this? Wasn't time the thing that had kept me away for the past two (plus) years?

I mulled on this all morning at work and then it hit me. I have been lamenting how short my lunch breaks are and how they aren't really enough time to get any significant project work done. (Particularly since I have no access to wi-fi at work and no place to secure my laptop when I'm not on a break.) But thirty minutes is a fairly decent amount of time to spend with a little pseudo code or an algorithm. Thirty minutes a day for five days a week is even better. ((rubs hands together with an excited grin)) I can take a break and do something at the same time!

This isn't to say that I expect to have a real chance at winning. But the rules of the contest require that at least ten people participate, so even if I get just a few solved this month, I'll be contributing to the quorum needed for there to be a winner. That's worth making time for. (That and playing with code is just plain fun!)

Tuesday, May 6, 2014

A Tiny Rant (Confession?) About Typos

I spent hours today slaying typo bugs. Silly, stupid, asinine one or two character typos that I shouldn't have made in the first place, or at least should have caught as I was typing them. There's one more out there in the wilds of my code that I'm going to spend twenty minutes looking for tonight. If I can't find it by then, I'm switching tasks and hitting it again in the morning. (Alarm's already set for 4am.)

I know that one solution is to sleep more. I've been around the block enough times to know that I make stupid mistakes when I'm overtired. Another solution is to drill my typing more. I have a plan for the latter: Typing.io is a freemium online typing tutorial that uses actual code for typing practice. I'm going to do a quick drill tonight right before bed and plan to build it in to my am/pm routine.

The former is a bit more difficult. I'll chew on that while I type tonight.

P.S. Oh, and there's this great one-liner for debugging Capybara that the great Philip Crawford introduced me to. Add save_and_open_page as a breakpoint in your failing test. It will give you a little snapshot on what on earth is going on. For more, see: Jeff Kreeft Meijer's blog post.


Monday, May 5, 2014

Strange Errors Are Good

Or, How I Learned to Stop Worrying and Love the Feedback.

((crickets chirp))

Well, then. Ahem. 

I've been plowing through a few RSpec tutorials (here and here), trying to increase my understanding and decrease my mind-numbing fear of all those error messages. Intellectually, I understand that error messages are our friends. The kind of friends who want to make us better and are willing to use some tough love to get us that way. Deep down inside, there's still that little part of me that makes my heart jump when I see a screen of errors go flying by. It's the same little panicky part that I successfully subdued into calm at the sight of the command line. I subdued the panic then and I will do it again.

In the meantime, I'm learning great things about RSpec though my little detour in tutorial-land.

Today I learned:
1.  You can run all of the tests in your spec/ directory by typing rspec spec (or rake exec rspec spec in Rails) on the command line. Frying pans! Who knew?

And, more importantly:
2.  Yes, at least at this point in my experience and training, it is totally worth the time to read through the entire tutorial first. It's tempting to just jump in and start hacking, but ultimately it's much more frustrating when I try to follow along. I typically end up hacking away and then I don't scroll down to see that the error message I think is due to some mistake on my part is really all part of the whole BDD/TDD plan. And, yes, I should have learned this lesson quite some time ago but it was hammered in today when I read through the tutorial before even opening my editor. I saved myself a ton of time and tears.

Sunday, May 4, 2014

Lesson #1 From TDD: Do Not Fear Errors

Test-Driven-Development is really a bit of a misnomer. It's really more like Error-Driven-Development. In a (nearly over-)simplified form, you write and then run your tests, read the error messages and then write the code that will prevent those errors and failing tests.

The first lesson for me (and perhaps for you, too) is to resist the gut reaction of "oh, no, I suck at this" when errors and test failures come up instead of automatically passing tests. Theoretically, I understand that we're going to get more failures than successes in TDD. It's convincing my subconscious that all of those 'F's really are expected and OK.

I've been working through the Ruby for Newbies: Testing with RSpec tutorial over at Nettuts+. That brings me to my first lesson for TDD tutorials: read the entire tutorial first! I spent nearly an hour trying to figure out why I was getting a strange error when running the first test, only to scroll down a bit and see that we're supposed to get that error at that point of the tutorial. That's when I remembered a nearly identical problem (same problem, different error) while working through Michael Hartl's Rails Tutorial. Sigh...

Tee Design by CoryWayDesign

Enough introspection. Back to the fray!

Saturday, May 3, 2014

Two Steps Back === A Better View

After finding some success with shot-in-the-dark code snippets from StackOverflow, I'm listening to Vizzini and going back to the beginning.

Luckily, I'm in a bit better shape than Indigo up there. But I'm just as far from my goal.
Back to the beginning, because blindly typing in the code from various tutorials and guides is simply not giving me any understanding and leaving me in utter confusion when I get errors.

I've put a few RSpec books on hold at my terrific local library and cast about for an online tutorial in the mean time. I found one by Jeff Nyman that I've actually tried before but was foiled by problems with Watir-Webdriver. CodeSchool has a paid course on RSpec, but I'm looking for the cheapest option here. There's a well-reviewed tutorial on NetTuts that's next on my list to kick around. I'll post my success or failure with it tomorrow.

Friday, May 2, 2014

Stubbing My Toe

Sorry about the yolk. I thought it was punny.

I'm still fighting my way through a series of failing tests in Rspec. Via this question over on StackedOverflow, I found a snippet of code that adds the create method to FactoryGirl. It got me past a few of the scenarios in the failing Rspec tests, but not all of them.
Next on the error stack is the missing email method. So, back to work for me.

Thursday, May 1, 2014

Practice Plus A Smidge of Inspiration

Today is the kind of day that I typically wouldn't blog about. (Ed. Every attempt to end that sentence with acting other than a preposition sounded silly, so I left it.) I didn't make the time to code because I had a very high-stakes VIP visitation at work today. The visit did not go well. It could have gone worse but it did not go well and certainly didn't turn out the way I worked so hard to make it. Overall, it has been a depressing day.

I'm blogging because it's a new day. I have no wisdom to impart. Tomorrow will be better, though, so I should have something interesting to say then.

Edited to add: The Complete Flake's Guide to Getting Things Done by Sonia Simone just popped to the top of my Pocket queue. Even if you're not a flake, there are some gems in there and it's definitely worth a look.