fhwang.net

ruby

validates_with_block
Friday, July 18, 2008

In one of our Rails projects at Diversion Media, our models can get pretty big with validations -- one in particular has almost 20. It ends up being pretty noisy having all those repeated words:
class User < ActiveRecord::Base
  validates_presence_of   :login, :message => 'Please enter a login.'
  validates_uniqueness_of :login, :case_sensitive => false
  validates_format_of     :login, :with => /\A\w*\Z/
  validates_length_of     :login, :within => 4..15
end
So, we wrote validates_with_block, a Rails plugin that allows you to write a more readable set of validations for one model.
class User < ActiveRecord::Base
  validates_login do |login|
    login.present   :message => 'Please enter a login.'
    login.unique    :case_sensitive => false
    login.formatted :with => /\A\w*\Z/
    login.length    :within => 4..15
  end
end
These methods just call the same old validates_* methods; they don't do anything interesting with ActiveRecord beyond that. It's just for keeping things readable, but sometimes readability takes a little extra work.

Tagged: ruby

Conversations vs. Laws
Saturday, December 15, 2007

The full RubyConf videos are now up. Included in this batch is my talk, “Conversations vs. Laws: What do we mean when we say Ruby is dynamic?” I got to jam in a bunch of tangential interesting ideas, and somehow found a receptive audience to them. The only blemish on the experience was that Laurent Sansonetti was giving his OS X and Ruby talk in the other room, so I had to miss that. Good thing for video.

Tagged: ruby, nature

RubyConf 2007 talk (slides only)
Saturday, November 17, 2007

Video for the RubyConf 2007 talks is coming, or so we’ve been told: The good folks at Confreaks seem to be churning away at what is most likely a massive post-production job. I’ll be sure to point to the video of my talk when it’s out.

In the meantime, here’s a dorky game we can play: If you didn’t see my talk at RubyConf, download the PDF of my slides, and then try to figure out what the hell I was talking about. As I’ve said before, my talk slides are usually this confusing without the accompanying talk. Is it hopelessly smug to suggest that this should be the case for more talks?

Tagged: ruby

RubyConf 2007
Wednesday, November 7, 2007

Another year, another RubyConf. 2007 was bigger than last year, maybe with an attendance of 500 people, and it’s hard to say if it’s kept any of its intimacy. The new semi-two-track approach (single-track in the morning, double-track in the afternoons) seems a good middle-ground to me. The only problem is that it’s probably nigh-impossible to predict demand when you’ve got two tracks. There were many afternoon slots in which one of the rooms was packed, the air dense with nerd-musk. Not a good thing.

The conference program overall seemed to have a highly theoretical, philosphical focus: Marcel Molina talked about beauty in code, Luke Kanies talked about Gödel’s incompleteness theorem, and then I talked about post-structuralism and dynamic typing. I was genuinely prepared to have the talk with the least amount of code, but then Luke had none at all, so there you go. Anyway, I enjoyed this aspect of the conference. It’s like we’re becoming a sort of OOPSLA-lite, which is preferable to becoming the next Java One.

I left this conference excited about the year ahead, for lots of different reasons:

  • The one-two punch of JRuby, which will tempt more of the enterprise world into Ruby-land, and Rubinius, which will make it easy for programmers to contribute to an implementation without being C wizards.
  • RSpec upcoming Story framework, in which high-level tests can get expressed in re-usable, described blocks. I don’t have the problem of needing to make these tests readable and writeable by non-techies, but I sure do have a lot of too-long integration tests in the Rails apps I write.
  • Treetop, an easy-looking DSL for text parsing. I don’t know much about parsing and am not sure when I’d use Treetop, but it certainly seemed simple.

I also ended up leaving with a few questions that will have to be explored further:

  • Is my sense of testing completely different from that of others? Why is it that nobody seems to feel the same about mocking and stubbing as I do? Why am I fine with writing less longer tests instead of lots of shorter tests? I have a feeling that I’m writing good tests, and that other people are writing good tests, but that there are nonetheless some fundamentally different mental models being employed here.
  • What’s up with the resurgence of attempts to transparently map Ruby to SQL? Jim Weirich brought it up during his talk as a learning exercise only, but a later Google search reveals Ambition. Having gone partway down this path years ago with Lafcadio, I’m not sure what to think. Ambition seems to use ParseTree, which would overcome some of the limitations of Lafcadio’s approach. But working with Ruby query inference in Lafcadio made me wonder if the idea’s a good thing at all. More on this later …

Tagged: ruby

Speaking at RubyConf
Sunday, September 9, 2007

I’ll be speaking at RubyConf again this year, for the third time. The title of my talk is “Conversations vs. Laws: What do we mean when we say Ruby is dynamic?”, and it’s basically going to be a potpourri of random ideas that may or may not be related to software engineering, such as Islamic art, restorative justice, anarchism, queer theory, and Platonism.

Ruby-interested readers will probably have noticed that my contribution to open source in the form of code has dropped like a stone in the past few years, so when I was thinking about doing a talk this year, a more abstract subject seemed like my best bet. Of course, now that my talk has been accepted I have to actually research the thing, and now I’m thinking it might’ve been easier just to write a few thousand lines of code …

RubyConf is from November 2-4, and it looks like tickets are still on sale. Tickets sold out last year within hours, so if you’re interested in going this year, you should buy immediately.

Tagged: ruby

(Very late) GoRuCo wrapup
Sunday, May 27, 2007

So, the first GoRuCo came and went more than a month ago, and not a peep out of me here. What can I say? I was tired.

I’ve been going to Ruby conferences for four years, and at each conference there’s always a point where I find myself wondering what happens in the next 12 months as a consequence. What new collaborations take shape? What new opinions get formed? What changes? What stays the same?

A month later, there are a few developments that GoRuCo might have played a part in:

  • After we announced that GoRuCo would be offsetting its carbon emissions, NYC Rubyist John Murch started green-tech blog Hippy Green. Certainly we’re not the only Ruby or Rails conference that’s charitably-minded: RailsConf, for one, raised $33k for charitable causes this year. We chose to donate as an organization, forcing attention on an issue: RailsConf’s decision to let attendees make a choice focuses more on the act of giving itself. All around a good bandwagon to have.
  • I feel like almost every time the organizers met, we ended up talking about gender in the Ruby community, possibly at my prodding. So I was happy to see organizer Gregory Brown later bring up the subject on the O’Reilly Ruby blog, which spawned lots of healthy discussion. Tim Bray brought this up again at RailsConf and blogged about it, too. I’m with both of them. The gender disparity is a big problem, and it needs to be fixed. And, by the way, IRC comments like “if we wanted women we would have become nurses” don’t help.
  • Without giving away too much, I will say that one prominent Rubyist seemed to be having a great time with us at the afterparty and out on the town after we closed the bar. Later he moved back to New York. Coincidence?

While all the talks were buzz-worthy, the one that seemed to most buzz-worthy in the “I could start building something with that next week” sense was Jay Phillips’ VoIP framework Adhearsion. I wonder if anybody in NYC has built any Adhearsion apps yet? Let me know if you have.

Tagged: ruby, nyc

GoRuCo 2007 tomorrow
Friday, April 20, 2007

Less than 24 hours from now, we’ll kick off the first ever Gotham Ruby Conference, at Google’s Chelsea offices. I’m pretty excited about the talks and about all the people coming together for this event, even though there are still a hundred things to worry about between now and when we open the doors at 9 a.m. tomorrow.

The conference has been sold out for a while, but if you’re in the area and want to stop through, you might want to know that the afterparty is open to the public. It’s at The Musical Box, on Avenue B between 13th and 14th Streets. As a non-attendee, you don’t get any drink tickets, but there will be lots around. You’ll probably be able to mooch a few.

Tagged: ruby, nyc

On GoRuCo, and chix who dev
Friday, April 6, 2007

Thanks to Shari Halter for interviewing me over on DevChix. I won’t claim to be much of a chik myself but I like what they’re trying to do on their site.

One of the things discussed in the interview, of course, is GoRuCo, which is sold out. Out of 120 seats, I believe we have 7 women—actually a better ratio than many other Ruby and Rails conferences, but that’s not much of an accomplishment.

I don’t feel as if I have any special insight as to why the gender gap in our field is so persistent, and I probably wouldn’t say that it’s anybody’s fault in particular. But it’s a serious problem—any field that’s so stupidly lopsided is bound to miss important perspectives—and it’s not going to go away in one broad stroke. The imbalance will be with us for a long time, but that’s no reason to ignore it.

How to fix it? Hard to say. GoRuCo doesn’t do anything overt in our treatment of the issue, and if anything I think that most of the work to be done, at least locally, is at the NYC.rb level and not the GoRuCo level. It’s probably not about a few grand steps taken at once, but about a lot of little steps taken over months or years. Maybe that’s vague, but my thoughts on this are still coalescing and I’m always loathe to talk about things I might do in the future. But check in with NYC.rb in a year and see how we’re doing …

Tagged: ruby, nyc, gender

Gotham Ruby Conference
Sunday, February 4, 2007

I already posted this on ruby-talk a few days ago, but it bears re-posting: We’re hosting a regional Ruby conference in New York City on April 21st.

The Gotham Ruby Conference is a one-day Ruby conference that will take place in New York City on Saturday, April 21st.

The lineup of speakers has yet to be determined, and will be determined with an open call for proposals. There will be six speakers, and an open lightning round for short talks. Speakers will receive free admission to the conference, an honorarium, and travel stipends are available as well.

Registration attendance is limited to 120 people. Tickets are $100 each. Registration will be open within the next few weeks.

The conference will be held at Google’s office in Manhattan. Breakfast and lunch will be provided.

To keep up with conference updates, subscribe to our RSS feed.

GoRuCo is a joint effort by volunteers from NYC.rb and the New Haven Ruby Brigade.

Local Rubyists should check out the Call For Proposals: At least 3 out of the 6 speaker slots for residents of New York, New Jersey and Connecticut. The deadline is March 1st.

Tagged: ruby, nyc

Starting a local Ruby group
Sunday, November 26, 2006

Ruby-NYC held its first meeting in February 2004, in the conference room of the New Museum of Contemporary Art. Three people showed up, including myself. Back then, the world of Ruby was much smaller: Rails was but a twinkle in DHH’s eye, and the RubyConf I had attended the previous October was only around 40 people. Two-and-a-half years later, we have up to that many people showing up to our local meetings. I’m not sure if I can take any credit for it, but it’s fair to say that Ruby-NYC is a successful Ruby group.

Tagged: ruby