I mentioned a few posts back that I was learning Ruby, and that I was going to start a project with it.
That’s still true, but I got sidetracked playing with C. It sounds strange, but I was getting frustrated with Ruby’s high-level abstraction – it’s hard to tell what’s really going on sometimes.
I’ve been playing with libcurl, libxml, and PCRE. I chose those in particular because they provide functionality that I typically associate with higher level languages. In fact, many higher level languages provide wrappers around libxml and libcurl for XML parsing and web file transfer.
It was a little painful at first, but once I got used to it I’ve been having a lot of fun. I’ve spent most of my time reimplementing things I’ve previously written in Perl or Ruby, trying to match the behavior of the script as much as possible. It’s really just highlighted what I knew all along – high level languages let you focus on what you’re trying to do using fewer lines of code.
One example that really illustrates that point is a simple program that grabs posts from Twitter. The Ruby version is a mere 35 lines:
The C version is way too long to show here, coming in at 275 lines, but it’s not an entirely fair comparison. The C version is more robust, has better comments, an 18 line license, and is broken up into (somewhat) reusable functions. If I really wanted to cut the line count I could probably get it under 200 lines, but it’s never going to be as svelte as the Ruby version.
I’ll probably add some more of the code to Github in the next few days.