Sporkmonger

purveyor of fabulously ambiguous eating utensils

FeedTools 0.2.27

Posted by sporkmonger
Written January 31st, 2008

It’s been a long time coming I guess. Haven’t really had much time to work on it, and when I have, I really haven’t wanted to. Of all the software I’ve ever written, I consider FeedTools to be the most embarrassingly bad. Ironically, it’s probably also the most popular piece of software I’ve ever written.

Anyways, it’s been so long since I made some of the changes that I have listed in the CHANGELOG that I don’t even remember making them. They probably really did happen. Everything finally green-bars in any case. I ditched HTree and replaced it with html5lib. I was surprised by how easy the transition was, but it’s definitely slower for it. I fixed the issues with resolving relative URIs. Got rid of some ugly hacks, added a few more. The schema for the cache changed slightly. On balance, it’s better than 0.2.26, but in keeping with tradition, it’s also a little slower. If you need speed, you’ve come to the wrong place. That hasn’t changed at all.

I’ve learned a lot in the time (What has it been now? 3 years?) since I originally set out to write this parser. Certainly the most important lesson I learned was, “If you build on a lousy foundation, the entire thing’s going to be unstable. At best.” I’m not sure why I didn’t realize much earlier on that REXML was a mistake. Once I was far enough in that I couldn’t easily turn back, I started trying very hard not to make the original mistake in other areas. Incidentally, that’s how Addressable came into existence. It became clear to me that Ruby’s built-in URI parser was terrible, so I stopped using it and wrote a replacement. A replacement that I now swear by. If FeedTools is my greatest embarrassment, Addressable is (for the moment) my pride and joy. (Actually, that might be a bit much. It’s still just a URI parser.)

Also, while I was at it, I put the API up again.

Hopefully I won’t have to touch FeedTools again for a very long time.

Introducing Addressable

Posted by sporkmonger
Written September 5th, 2007

So, after 3 months, I’m back from my excursion to Africa. Don’t worry, I’m not coming back empty-handed.

I thought my fellow rubyists might benefit from the URI implementation I’ve been using in various projects, so I’ve extracted it out into its own library. In the process, I improved a few things here and there, added support for URI Templates, and fleshed out the specifications a bit more.

I introduce to you the Addressable library.

It has about a 2:1 spec to code ratio, 100.0% code coverage, and it has gone through plenty of code heckling. It ought to be pretty reliable.

Hope you like it. Let me know how it works.

Update:

I’ve added URI Template variable extraction and I updated the documentation. The extract_mapping method should be useful for template-based routing systems for frameworks.

Relaunched, Realigned

Posted by sporkmonger
Written April 2nd, 2007

If you can see this, apparently everything is working.

Update:

Ok, so there were some bugs. Incorrect permissions and such, not-quite-right Apache settings. But it’s likely to be more functional now.

After several weeks of work on the site, I’ve finally gotten everything moved off Typo, redesigned, and generally just looking a thousand times better than before. I also hosed out all of the accumulated spam. It wasn’t easy.

At Aristotle’s request, I made sure to modify the Typo conversion script (as well as Mephisto itself) to allow the feed entry GUIDs to remain the same. I wasn’t particularly pleased to discover that Mephisto doesn’t actually store its entry GUIDs in the database—it generates them each time the feed is requested, which in my humble opinion is a terrible idea, since the information it uses to generate the IDs might change. The change I made added a “guid” column to the database and uses UUIDTools to generate unique ids instead.

I also deleted a bunch of entries that I no longer felt were relevant to the site. I know a lot of people in the pro-standards crowd don’t like it when people do this, but I did anyways. I also tried to set up redirects for all of the old resources to the equivalent URIs in Mephisto, but I’m sure I missed a couple. If you bump into a 404 that you think is a mistake on my part, I’ll try to get it fixed as quickly as possible.

In addition to the switch to Mephisto, obviously I also took the time to redesign the site. I figured I should construct the design entirely from scratch this time instead of simply altering the default Typo theme. I gotta say, I really, really, really like the new look. I haven’t bothered testing and seeing how it looks in Internet Explorer. I really just don’t care that much about IE anymore. But I didn’t do anything particularly tricky with the design either, so it’ll probably look mostly OK. If you’re reading this in IE, stop, go install some other browser (preferably Firefox), and then come back. Web developers everywhere will thank you for it. And you’ll feel better about yourself. I promise.

I released a new library the other day called Squish. Admittedly, in its current state, it’s really effectively useless. I’ve never been particularly good at optimizing for performance, and while I did manage to improve the speed of the library (with the help of people in #ruby-lang) by at least an order of magnitude, it’s still way too slow to be useful. In retrospect, I’m not really sure why I even tried to write it in Ruby—I really should have known that a compression-based text classifier would need to be written in C. But hey, at least I know the basic idea works now.

Oh, and you may also notice that the site is faster and less error-prone now. You can thank Slicehost for that. I can’t recommend them highly enough if you’re in the market for a Rails-friendly VPS host.

Project List

Posted by sporkmonger
Written April 1st, 2007

I’m willing to admit to being responsible for:

There’s some other bits of code floating around in various states of disrepair.

I’ve also got a couple of C libraries I’m working on, but I’m not likely to talk much about them until they’re further along.

Instance variables, class variables, and inheritance in Ruby

Posted by sporkmonger
Written February 18th, 2007

I’m seeing a lot of code that indicates to me that people don’t have a complete grasp of when to use class variables in Ruby.

Here’s a quick example script that should give people a better idea of what’s going on:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

class ExampleClass
  @variable = "foo"
  @@variable = "bar"
  
  def initialize
    @variable = "baz"
  end
  
  def self.test
    puts @variable
  end
  
  def test
    self.class.test
    puts @@variable
    puts @variable
  end
end

class ExampleSubclass < ExampleClass
  @variable = "1"
  @@variable = "2"
  
  def initialize
    @variable = "3"
  end
end

first_example = ExampleClass.new
first_example.test

puts "---"

second_example = ExampleSubclass.new
second_example.test

Output:

foo
2
baz
---
1
2
3

Essentially, when you declare a class variable in a base class, it’s shared with all subclasses. Changing its value in a subclass will affect the base class and all of its subclasses all the way down the inheritance tree. This behavior is often exactly what’s desired. But equally often, this behavior is not what was intended by the programmer, and it leads to bugs, especially if the programmer did not originally expect for the class to be subclassed by someone else.

I strongly encourage Ruby developers to sit down and think about how they want their classes to behave if subclassed by someone else. Be careful about using class variables, because often what you actually wanted was an instance variable on the class object.