TDD Day 2 Preamble

*I really hate long blog posts, but this should be an exception to future posts on this topic*

Where’s TDD Day 1?  It doesn’t exist.  Why? Because I decided to start writing about my experience after day 2.

I’ve read countless studies, testimonials, love letters, etc about how TDD and how awesome it is.  I’ll confess, I’ve tried it before – only to fall flat on my face at every turn of the road.  I’ve read tutorials, books, blogs, and articles, but it’s never clicked for me.  It’s one of those skills I wish I had, tried to attain, and realized that I just suck at this.  But like all things, practice makes perfect.  For the time being, I’m simply going to be writing tests, then writing my code.  In my previous attempts at TDD or just unit tests in general, concepts like mocking made sense, but when it came time to code, I could never get it to work. So…. in the meantime, mocking is taking a back seat to simple stubs.

I’m not against TDD.  In fact, I’ve fallen in love with just simple old unit tests. I’ve seen their benefit when a change I made broke code elsewhere — important code.  With the few forays it’s taken me to write my code and try to do it in a TDD fashion, I have had the chance to place my stamp of approval, and that’s an unbelievable feeling.  When someone questioned my code, I had the ability to say “No, I know for a fact that it does this and not that” as opposed to the usual “It should be doing this… let me run it and check just to make sure.”

In college they tried to teach use to write unit tests. However, the manner in which they represented it was complete and utterly useless.  For example, they’d have us write a test to verify that adding two numbers equalled what we expected it to.  Sure, this is a great toy intro test, but in the long run, those learning have no idea why you would write four fold the amount of actual code to test cold hard facts, such that 2 + 2 = 4.  Programmers are lazy – it’s what makes them efficient, so as a result, it’s a skill that goes unlearned and never practiced.

Tell a manager that your code will take 40% longer to write and see what happens.  You’ll likely get the response of “yeah, I don’t think that’s a good fit for us.” Only to spend an entire week testing medial code to make sure it didn’t break something somewhere else – and doing it by hand, which everyone knows is prone to more human error than code error.  There is merit in human testing – but there’s a fine line in testing something that could be done automatically. The studies have shown that although it takes longer, maintenance time is cut and code quality improves.

Maybe you don’t like TDD or agree with it.  That’s fine, but at least recognize the usefulness of unit tests.  I remember sitting in an MVC user group when a speaker said “we’re all doing testing right?” and the silence in the room was like a black hole. This speaker was mostly a Ruby guy and luckily, this was around the time when I started toying with Ruby and Ruby on Rails.

I’m a complete noob when it comes to dynamic languages like Ruby and Python, but I’m getting better.  What I especially enjoy is the culture of those communities and how they embrace these methodologies which we should all be doing.  For example, I know Rails is very opinionated – but in a good way.  If you don’t write tests for example, you’re an outlier – but people are willing to help you out.  Maybe its the fact that there’s no type safety in dynamic languages and it leads to insecurity about code.  Whatever it is, I love it.  I love that I suck at it, and I love that it gives me room to learn and grow.

Onto the actual code! TDD Day 2!

Why Iron-Man and Batman Are the Best Heroes

Why are heroes like Iron-Man and Batman the best?  Because they’re not super.  That’s right – they’re not superheroes, they’re simply heroes.  At full disclosure – I have no disclosure.  Everything I know about these heroes comes from the trading cards I had as a child, from the movies, the video games, and from speaking with those who are more familiar with these characters.

But what makes these heroes better than all the other ones?  For one, they don’t suffer from guilt.  Many of the super heroes do what they do because they feel guilty having such powers and not helping mankind.

“With great power comes great responsibility.”

Really think Superman feels super when he’s interrupted in the middle of eating a cheeseburger?  Not to mention he has to carry that persona of Clark Kent – so now he has to overpay for his meal, so as to not underpay what it’s cost including tip, leave it half eaten, and rush to the bathroom to stash his clothes in some waste basket for the time being while he saves a woman from being robbed.  Fuck that.

Iron-Man is an womanizing, egotistical, drunkard genius who’s made his riches through his engineering marvels.  Although he has his demons, the reason he is awesome is because he does what he does because he wants to.  People know who he is and he has the ‘what are you going to do about it?’ attitude.  He’s self made and he has NO super powers.  He’s vulnerable to everything and every range of human emotions.  He’s something kids and adults alike can aspire to be – sans the non-desirable traits.  He encompasses the American dream – the original core dream.  Rags to riches and helping the world because he wants to.

The same goes with Batman.  Although his fortune is inherited from his parents, he still manages that ridiculous company of his to profits.  He fights crime because he wants to.  There might be something about finding the people that killed his parents, but like I said earlier — I’m not too familiar with the story.  Either way – he’s just a really smart dude, with kick-ass techy stuff, fighting bad guys.  The guy willing to take the fall if it helps his city.  The guy who loves only one girl – the one he can’t have.  The guy living in the shadows, receiving no credit outside of his disguise for what he does.

But maybe I’m wrong in considering these guys as real heroes.  Maybe I have the story all wrong.  Maybe I really cannot relate to any of them.  Truth be told, they’d probably lose to any of the X-Men, or Superman, or Spiderman, or any multitude of heroes that actually have super-human powers.  However, to me, they embody everything that is human and everything we should strive for.

*In this class you can also include the Punisher, as he is also a bad ass.

Unrealistic Goals and Expectations

Last night I had the pleasure of helping someone test for their next rank at the dojo.  To my dismay, the person was extremely disappointed with himself for only being promoted one rank instead of two.

Are you kidding me?

I understand how it feels to fall short of a goal you’ve set for yourself – it’s depressing.  But setting yourself up for failure by creating unrealistic goals and expectations is asinine.  Studying a martial art takes skill, practice, dedication, and most important of all patience.  It’s an old addage that by the time you truly understand a martial art, you’re too old to practice it.

As I congratulated this person on their achievement, I reminded them that what they had done is not easy – if it were, then everyone would do it.

What I find interesting is how this mirrors what the software industry has learned over the years.  In my very short time as a developer I’ve come to understand why methodologies like agile have taken hold and become desirable.  It’s because you set an overall goal – which many or may not be realistic.  However, by setting smaller, definable, and achievable goals through units of code (if you will), we better realize if the overall goal is realistic – and adjust it to meet the requirements while maintaining a firm grasp on what you’ve already accomplished.

If this person whom I helped test had set the goal of obtaining one rank higher as opposed to two – he would have laid a better foundation in his skill and probably found a new technique to add to his common repertoire.  However, by attempting to do something that’s incredibly difficult and not very common – he cheated himself by spreading himself too  thin – achieving maybe only 50-70% efficiency in 20 techniques rather than 100% efficiency in 10.

will_paginate + Rails 3.0.1

Recently, I came across the issue while attempting to implement will_paginate with Rails 3.0.1. I did the usual inclusion of the gem into my gemfile:

gem 'will_paginate'

I was greeted by the following error when accessing the method in the controller: “can’t convert nil into Array”. Upon further investigation, the installation notes for will_paginate tell you to modify the will_paginate line in your gem file to:

gem "will_paginate", "~> 3.0.pre2"

Of course, it worked like a charm. I guess they’re still providing updates to the gem for an actual release for Rails 3 — so if you were updating from a previous version of Rails and wanted the bleeding edge of will_paginate, you’re bound to run into this problem.

And a side note: read the documentation >.<

The Best Way To Ship a Package

I logged in to Amazon to check the status of an order I had placed. I was more than happy to see that my package was being shipped in the best manner yet – on an interstellar Lasership. If only we had time travel, I could have had the package before I even ordered it…