Rails Test Prescriptions Blog

Keeping Your Application Healthy Since 2008

July 14 2010: The Smallest Thing

Book Status

Still working on the legacy chapter. The sidebar here is that deliberately writing bad legacy code for purposes of using as examples in a book is a little challenging. It’s got to be tangled enough to make the point that it’s hard to clean, but small and clear enough to work in the context of a book example. My tired brain was fighting it last night.


I mentioned this recently, but I want to mention it again. I’ll be teaching Obtiva’s Advanced Ruby on Rails course Aug 30 – Sep 2. This is going to cover a lot of non-novice topics. We’ll be building in Rails 3 and (I hope) Ruby 1.9.2, and covering security, performance, rich experience tools, deployment, and the like. It’s a new course, and I’m excited to put it together. I’ll most likely be quizzing early registrants to determine exactly what to cover. Follow the link and enter your information on the form.

The Smallest Thing

So I was talking yesterday, and later twittering, about the smallest issue that I might see in a potential candidate’s code sample that would almost disqualify that person in my eyes.

My first answer to this for Ruby is 4-space indent. Because it’s totally trivial on the one hand, but on the other goes against an extremely well-established community norm, indicating that either the person isn’t engaged with the Ruby community or is really, really stubborn. Neither of these is a recommendation.

Other people suggested different things — here are some of the most trivial:

@wxwill said “for and while loops”. Yeah, that would be an issue for me as well, same reason.

@aberant: suggested STATEMENT rescue "". I might give somebody a pass if that was used reasonably once, but it would look weird in a code sample.

@johnashenfelter suggested Hungarian notation, which would probably disqualify a developer for me in almost any language that was not actually C. He also suggested CamelCase, which would also act like four-space indent for me.

@mileszs mentioned explicit return statements. I sort of agree, although I see that as less of a problem than some of the others, in part because it’s easy for an explicit return to slip into code, at least for me. I find when teaching Ruby that this particular community quirk is particularly hard to justify to people coming from, say Java. To them, it feels like deliberate obscurity. Though I think once you get the hang of expression-based Ruby, it seems perfectly natural.


5 responses to “July 14 2010: The Smallest Thing

  1. mikewoodhouse July 14, 2010 at 9:16 am

    While I completely agree for the most part, one member of that list leapt out at me. I’m going to have to come clean here and admit that I sometimes don’t see a sensible alternative to a “while” loop.

    I don’t use them for iterating on Enumerables, nothing like that, but sometimes I need to keep on performing an action while something (or until something) is true (or false). I usually feel a bit dirty and non-Rubyish while (or until) I’m doing it. Then, after suitable meditation I do it anyway.

    Example: the legendary tweetable Mandelbrot set (http://www.heartmindcode.com/blog/2010/04/twitterable-mandelbrot/) has an “until” loop that is – to me – appropriate: the termination condition depends on values calculated inside the loop.

    So is it always bad, or just something to be used with awareness?

    • noelrap July 14, 2010 at 9:23 am

      You’re right — there’s sometimes no alternative to a while loop, even though it feels weird. A for loop, though, usually indicates somebody that doesn’t understand Ruby Enumerables.

  2. Pingback: Ruby Learning with Java Habits | Code Cheese

  3. iterology July 26, 2010 at 6:52 pm

    I am just so embarrassed– I had no idea the indentation thing was a standard. Just wrote a script to halve all of the indents in my code.

    • noelrap July 26, 2010 at 10:01 pm

      I can’t tell if you are kidding or not. If not, It’s nothing to be embarrassed about… even if I wasn’t being tongue in cheek, it’s more about being engaged with the community than anything else.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: