« Resources for Synchronous Reads, Asynchronous Writes at RubyConf 2009 | Main | Why Mark Suster is wrong about not hiring job hoppers »

December 30, 2009


Jeremy Voorhis

I like it! But I wonder if at some point the Ruby community should consider using boring names, e.g. Net::Domain, instead of coining a neologism for every release :)

Avdi Grimm

What advantages do you tout over Addressable::URI?

And I for one like the name. The trouble with "boring" names, as Mr. Voorhis suggests above, is that they are prone to naming collisions with other libraries which are trying to do the same thing. Boring names like Net::HTTP should be reserved for the standard library.

Then again, I named one of my projects HookR, so I could be biased ;-)

Paul Dix

I wasn't familiar with Addressable::URI, but at a glance it seems as though it presents the same basic functionality as the standard library URI. The problem I needed to solve with this library was identifying subdomain, domain, and tld (not just the full host).

I also needed something that could create a canonical representation of URLs. This is helpful if you're indexing off this and want to do a site search or something. If I index a bunch of pages and key off the canonical URL the query to show everything from this site would be two starts with queries like this:

That doesn't seem to be something that Addressable::URI supports. As for names, I'm a big fan of coming up with memorable and searchable library names (since they're not part of a standard lib). However, I generally try to use descriptive class names within the libraries I write.


Those few new bits just don't justify creating a whole new library that duplicates tons of functionality in the Ruby standard library.

Why not submit a patch for URI instead? We already have URI#parse and friends; it's got a host method, so why not extend it with your domain-specific extensions? If you don't want it to be a part of the standard library, just monkeypatch URI with those methods:

class URI::HTTP
  def tld
    host =~ /\.(\w+)$/ ? $1 : nil  # Or whatever
  # …


>> URI.parse("http://foo.com/").tld
=> "com"
Paul Dix

Hi Alexander,
Getting the tld is actually trickier than that. Have a look at the public suffix list. Sometimes the known suffix is two or three dots deep (co.uk, *.*.jp, etc). As for adding to Ruby, I'd be more than happy if ruby-core took it, I just don't see that happening. Easier to write my own library.

Finally, I don't like monkey patching other people's code for public release. If it's something in my own code base, fine, but not if it's something I'm going to share with the world.

The beauty of gems sand OSS is that I can write something really small that has use for other people and easily distribute it.


I was searching the web for ML in NYC, and somehow landed here.

At the cost of being unabashedly honest, might I say that I like your profile picture a lot :)

{as my ML professor in cmu used to say, 'dude, ML will make you stumble on unexpectedly attractive things in life'}

**apologies for the complete randomness**


Hi Paul

I like your gem better than addressable but if I pass Domainatrix.parse("index.html").domain to domainatrix I get an error. Addressable returns nil which is more correct.

What do you think?


Paul Dix

I haven't seen that before, but my first commit predates that project by about 30 days.

The comments to this entry are closed.

My Photo



Twitter / pauldix