Gears Within Gears

Seek simplicity, and distrust it.

Mansions of cards: Osinki, CDOs, and the role of software

Posted by Brian Guthrie Tue, 31 Mar 2009 01:53:00 GMT

The aim of software is, in a sense, to create an alternative reality. After all, when you use your cell phone, you simply want to push the fewest buttons possible and call, text, purchase, listen, download, e-mail, or browse. The power we all hold in our hands is shocking, yet it’s controlled by a few swipes of a finger. The drive to simplify the user’s contact with the machine has an inherent side effect of disguising the complexity of a given task. Over time, the users of any software are inured to the intricate nature of what they are doing. Also, as the software does more of the “thinking,” the user does less.

From My Manhattan Project: How I helped build the bomb that blew up Wall Street. Highly recommended; the article touches on the ethics of software development, user interface design, complexity, and the classic question of the degree to which a creator may be held responsible for the acts of his or her creation.

It is not Osinski’s fault that his software makes it very easy to perform some otherwise rather difficult algorithms; that is, after all, much of what a computer does. But it does make me wonder that he agreed to work on it understanding full well that the technique was built on entire mansions of cards, and it serves as an ample reminder that our moral compasses are so often attuned only to the values of those around us.

But what, then, is appropriate user design? Should business software be ugly, difficult to use? Should it, like a disassembled watch, expose its innards for all the world to poke and prod at? Must an operation that you suspect your user does not rightly understand always come with a warning label: “Don’t touch unless you really, truly know what you’re doing”? Isn’t that just condescending to your users?

Like everyone else, I’ve used my share of software that I absolutely loathed; software that made simple tasks hard and hard tasks devilishly impossible, their user experience an afterthought, a victim of shrinking budgets and small visions. If there’s anything I’d like to see improved in what you might term the ecosystem of enterprise software, it’s the fact that so much of it is, from a human point of view, really wretched. If you must make people use the stuff, don’t make them dread the experience.

But am I wrong? Should an ugly veneer serve as a reflection of inner ugliness, or of my own lack of understanding? I don’t know how many kinds of Photoshop filters work; should I as their user ask the designers of Photoshop for a poor interface design, so as to force me to pay a psychic penalty for my ignorance?

Of course not. As developers, our eagerness to please our clients and stakeholders is, after all, only human, and anyway, software projects do not have a great track record of success when it comes to satisfying the demands of their procurers. Some projects are wise and some are not; Osinki labored foolishly, although surely if he had not taken up the call some other equally talented developer would have. Agile development, I think, provides us with the tools to build software more rapidly and closer to spec than ever before; so let us then pick our projects wisely.

Posted in | no comments |

Code comments, alias_method_chain, extensions, and the importance of expressing intent

Posted by Brian Guthrie Fri, 27 Mar 2009 17:14:00 GMT

At ThoughtWorks, everyone submits a code sample as part of their interview process. The comment I received from my interviewer about mine struck me, though, and it sticks with me to this day. “The code looks fine,” he said, “but what’s with all the comments?”

My introductory CS course at Northeastern University taught me a lot of things that have resonated in my experience in the industry, but we were taught one thing that, as it turns out, almost none of my colleagues agree with: that all of your methods, classes, and modules should be preceded by a simple, one-line comment that states the purpose of code unit in question. Far be it from me to gainsay Neal Ford, who believes that code comments are a smell, but there are days when I disagree: Even developers with the best intentions and training in the world can’t always write clear code.

A Brief Re-Introduction to Class Re-opening

The problem manifests itself most acutely through the Ruby mechanism of class re-opening (sometimes dismissively referred to as “monkey-patching”). You can go about it in a number of ways, and the codebase I’m working on these days has employed each and every one of them at some point or another. The advantage you gain from being able to reopen classes is that you can patch the framework you’re using unobtrusively in order to fix bugs or improve performance. The downside is that you don’t get to choose the names of the methods you’re overriding: they may make perfect sense in the context of the class you’re overriding, but none whatsoever as an isolated patch.

A reopened class looks something like this:

In the first example, we’ve patched String directly; in the second, class_eval’d it for an added layer of complexity; and finally we’ve defined our own module and added it to String after the fact, which is fact the recommended way of going about it. We can use IRB and the method method to try to figure out where our patch is coming from:

Notice that only the last one gives us a helping hand when we’re trying to figure out where this method was defined.

Overriding, not extending

Now imagine there’s a bug in the String class: a colossally poorly-designed method, something that’s significantly impacting your ability to get something done in the language. (While this doesn’t happen in Ruby very often, it’s like to have occurred at least once in the framework of your choice.) In the bad old days, you’d have had to patch Ruby directly; if you were good about it, you’d submit your patch to Matz, and it’d get integrated as part of some future release. But the language itself gives you an escape valve: override the method, and your implementation gets used.

On my current project, we do this all the time.

But what happens when the framework gets upgraded? Is this extension still necessary? Why did anyone put it there in the first place? What’s with this Subversion check-in comment? Why didn’t anyone say anything in the code?

Enter alias_method_chain

alias_method_chain is a Rails method patched into Ruby that allows you to extend a method without blowing away the old version. You can read Marcel’s post on it on the Rails blog from back in the dawn of time, two years ago, when they added it to the framework. In action, it looks something like this:

Suddenly our extended method has an identity again: it has a name that clearly indicates both the method it’s trying to extend and the feature we’re adding on top of it. Hallelujah!

Why does this matter?

The ability to re-open classes is an insanely powerful tool. I love it, not least because it never means having to write another XUtil (XmlUtil, DateUtil, StringUtil…) class again to make up for the deficiencies of someone else’s API. I could never tell you, in good conscience, not to use it.

But cleaning up becomes a bit of a mess when you have to upgrade frameworks (or language versions, for that matter) as we’ve had to do recently on our project. We carry a copy of Rails around in our vendor directory, like most projects do, but we’ve tried to be good about making our extensions externally, through class re-opening, rather than patching the Rails code directly as men and women did in days of yore. But because, out of habit, none of these extensions carry any comments, we’ve had a devil of a time trying to figure out not what they do (we can always read the code) but why they’re there, and whether we can finally, for the love of God, delete them now that we’re upgrading to Rails 2.2.

But take it from me, one developer to another, who hath had to maintain thine extension, yea, even unto multiple new Rails versions: using the tips above will help me, and those like me, figure out what the dickens you were trying to do. And for Heaven’s sake, when you don’t have the luxury of naming your methods to make it clear what they do or why they’ve changed, leave a quick comment.

Posted in | no comments |

An introduction to mocking and stubbing in Ruby

Posted by Brian Guthrie Wed, 25 Mar 2009 04:11:00 GMT

I gave a presentation on mocking and stubbing in Ruby a couple weeks ago at the Atlanta Ruby Group and the maintainers of the group have been kind enough to put the video online. It’s a large and energetic group and I had a lot of fun presenting, as indeed I always have watching others present there. If you’re new to unit testing in Ruby and you’re wondering what the fuss is about, check it out and let me know what you think at btguthrie@gmail.com. Slides here, or just watch the presentation.

Posted in | no comments |

What the Rails Hosting survey says about the Ruby on Rails community

Posted by Brian Guthrie Tue, 24 Mar 2009 03:07:00 GMT

Some highlights, or anyway things that caught my eye, when I read the 2009 Rails Hosting survey of Ruby on Rails developers:

  • Around 60% of the community has been using Ruby and Ruby on Rails for 2 years or more. It’s not yet a mature community, but there is now a reasonably large body of expertise to draw from in solving problems in and around the framework.
  • Rails developers on average develop two to five new applications per year, and deploy them several times a week to several times a week.
  • Most of these are probably small:
    • Generally respondents either self-host or use a small-scale VPS service like Slicehost (which I myself host this blog on; recommended.)
    • Respondents claim to be highly sensitive to the price of their hosting provider.
    • Most don’t use performance, uptime, or process monitoring.
  • It surprised me to see that almost a quarter don’t use any automated deploy process whatsoever, which sounds painful. Furthermore, 5% claimed they were still using FastCGI+Apache. Crazy.
  • The community has largely moved over to Git as the SCM of choice, although Github is not widely used as a centralized code repository—only a third claim that their source code is hosted there.
  • Passenger has, this year, finally surpassed Mongrel as the rails server of choice.

I see a community that’s still youthful but is starting to mature. I’m still proud to be a Ruby developer, and glad to be a part of the community. Here’s hoping for more good years ahead.

Posted in | no comments |

Announcing the release of ResourceFull 0.7.1

Posted by Brian Guthrie Tue, 17 Mar 2009 01:03:00 GMT

ResourceFull integrates with ActionController to provide a comprehensive RESTful resource modeling and querying framework. It provides parameter queryability, paging, sorting, separation of controller concerns, multiple formats (HTML, XML, JSON), CRUD access permissions, and API metadata surrounding the resource itself. It’s opinionated but is intended to provide you with as much as possible without limiting your ability to customize its behavior.

This plugin was extracted from a series of Rails projects intended to serve as the services tier of a series of loosely-coupled applications built in a style reminiscent of the RADAR architecture.

ResourceFull lives on Github at http://github.com/bguthrie/resource_full/.

GOALS

The major distinguishing features of ResourceFull are:

  • Queryability: the ability to designate certain parameters as queryable, and map them to columns and SQL queries in the underlying model. These queries chain together multiple named or unnamed scopes and can be used either for a SQL SELECT or SELECT COUNT. This functionality may be moved into a separate plugin in the future.
  • Pagination and orderability: it automatically responds to requests for limit, offset, order_by, and order_dir.
  • Implementation: Default implementations for HTML, XML, and JSON controller requests.
  • API documentation: ResourceFull-enabled Rails apps are able to provide automatic documentation of the resources they expose, up to a point. (This is enabled in large part by the queryability functionality and other resource-level descriptors.) It’s my hope that this can eventually be consumed by a Rails resource registrar that acts as the single source of record for multiple REST engines within an organization.

EXAMPLE

This allows for the following:

/users/bguthrie.xml
/users?name=Guthrie
/users?email_address=gmail
/users.xml?city=Chicago&name=Brian,Paul,Alicia&order_by=city&order_dir=asc
/users.xml?limit=10&offset=30
/users/bguthrie/addresses
>> UsersController.to_xml
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n  ..."

API DOCUMENTATION

To enable ResourceFull to document your resources at /resources.xml and /resources//routes.xml, add map.api to your routes.rb file.

Posted in | no comments |

Onewaysweet: a way to track conversations

Posted by Brian Guthrie Thu, 05 Mar 2009 05:03:00 GMT

Onewaystweet is a simple Twitter mashup that helps you track what people are saying about your site, and when. It hashes the URL (using several different URL compression services, or at any rate, the ones that offer idempotent hashes of the given URL) and performs multiple followup Twitter searches so you don’t have to.

Robert Scoble thinks Twitter isn’t for conversations. That may be true, but that don’t mean that people ain’t sayin’ stuff. Pop in a URL, subscribe to the RSS feed, and follow the results. They may surprise you. Then again, they may not, which may also be surprising. Is disappointment a kind of surprise?

Actually, the queries that result in the greatest amount of buzz have certainly surprised me. Obie Fernandez’s minor mea culpa on the Rails Maturity Model generated a lot of controversy and results in (as of the writing of this post) a fair number of hits; the current New York Times headlines story does not. Is Twitter still so tech-centric?

On the technical front, I’m currently deploying it on Heroku, which was almost absurdly simple to do. As advertised: git push and you’re done, though the site doesn’t use a database and I can’t speak to the deployment experience in that regard. The fact that the developer preview is free certainly doesn’t hurt. Their explanation of how it works is sexy but short on gritty details. I’m okay with that, because in my idealized fantasy world deployment is always Somebody’s Else’s Problem. But the bitter Rake hacker in me is convinced that not having SSH access will be a huge pain in the patootie at some point in the future.

Posted in | no comments |