Eric Warmenhoven: Rewriting as a learning tool
So a year and a half ago, I mentioned I was trying to learn Haskell, and I still am. It’s been going much more slowly than I hoped, since I haven’t really spent any time on it. I never write anything new anymore! So I decided to rewrite something I had previously written myself, need be damned. So I chose the RSS aggregator I wrote, harsh.
harsh hasn’t changed in eleven months (and that change was just about making the location of its configuration file configurable), but I still remembered how it worked pretty closely; at least enough that I didn’t have to really go searching through its code too much. That’s probably also a function of how small harsh is; in terms of lines of code (excluding blank lines):
config.c: 139
cookie.c: 221
display.c: 709
feed.c: 577
list.c: 96
list.h: 16
main.c: 96
main.h: 84
md5.c: 360
md5.h: 76
rss.c: 120
xml.c: 276
xml.h: 17
total: 2787
It uses expat to parse the HTML, libnbio for socket management (which is available in Debian), and ncurses for the UI. It doesn’t have any sort of threading (libnbio does a good job of making sure that, other than DNS lookups, there’s never anything going on long enough to prevent responsiveness). About its only feature is that it will use my cookies.txt file, so that I can see my LiveJournal friends’ protected entries.
I originally wrote harsh in about a day or two. It was really easy because of the 2800 lines, about 850 of them had been written in some of my other projects (list.c/h and xml.c/h) or are standard (md5.c/h). I was also really familiar with the three helper libraries from writing grim (my IM client) and stark (a tool for viewing GnuCash data files).
As a learning exercise, rewriting harsh in Haskell was excellent. It’s incredibly small, does a lot of standard things (like networking and console UI), and doesn’t do a lot of non-standard things (like an AIM client does). I got to play with the Haskell light-weight threads and STM; I learned how to create a Debian Haskell package; I learned how to use ghci as a debugger with breakpoints; and I’m much more comfortable with monads and with the language in general.
It did take me significantly longer to write than the C version, though that’s more due to me having to learn not just the language but some libraries along the way (like HTTP, Vty, and HaXml). I still think that it would take me just as long to write the Haskell version as the C version, but I’m still much more comfortable with C, and imperative programming in general.
From a code size perspective, the Haskell version is about one-sixth the size (excluding comments):
Config.lhs: 53
Feed.lhs: 144
Harsh.lhs: 272
Util.lhs: 26
total: 495
However, that’s not a very fair comparison. In the C version, md5.c/h are included in the total count, when really they should be considered a standard library (and on the Haskell side, I used Data.Hash.MD5 from MissingH). On the C side, I did all of the HTTP request and response processing myself (which is what more than half of feed.c is about), while on the Haskell side I left that to an HTTP client library. Excluding all those things though, the Haskell version is still about one-fourth the size.
Anyway, I put the Haskell version of harsh up here. If any Haskell hackers out there could take a look at it and let me know what I’m doing wrong or oddly, I’d appreciate it.
After
Exim has the habit of trying to find out about its host names and IP addresses when it starts up. This has, in the
past, been an issue for the Debian packages, since a Debian system might be on a dial-on-demand modem line with
expensive costs and thus should not do unnecessary DNS lookup when the MTA is started.
This article tries to describe the issue and which countermeasures debian took, and asks for tips how to solve this in
the case of IPv6, where our past measures unfortunately do not directly apply.
I’d like to solicit opinions from people who are more experienced than me with Unix, the local resolver library
including /etc/hosts and /etc/nsswitch.conf, DNS, and - especially - the customs that apply on a system running IPv6.
To avoid the extra DNS lookups, the Exim packages have a Debconf option to configure exim for “minimal DNS
usage”, which hardcodes the hostname into Exim’s configuration at package configuration time. This was
necessary since - without this option - exim looks up its own host name in the DNS even when a completely local
operation is invoked.
In some cases, exim still looks up its IP address when a listening daemon starts up. This is why the Debian installer
configures 127.0.1.1 (not 127.0.0.1) for the local hostname on installation, yielding /etc/hosts files like
OK, been quiet for a few days, at least on the blog, but in accordance with typical behaviour (for me at least) a quiet blog means a lot of things going on elsewhere. The smallest was a fix for
For those that don't know, I'm running for local government as the Liberal Democrat candidate for King's Hedges City Councillor in Cambridge.
There are many reasons to hate Java, it's like shooting fish in a barrel.
But in the last weeks I found some more, half of them aren't even fault of the
standard API (the usual culprit), and I want to share my frustration with the
rest of the world.
It has no unsigned types
Say you want to manage binary protocols, files, etc. You'd like to
store and retrieve bytes and words in machine format, of course, but
you'll have a hard time finding the right value because you can't have
a goddamn unsigned byte!
So if you want —for example— to read the length of a string
which can be bigger than 127 as a single byte, you'll end doing some
aberration like this:




This post is both an attempt at replying to
For years, several important (or not so important) people have
forecast the end of email. While most of what they were saying
couldn t be disagreed with (important people always speak in vague,
vacant terms), it wasn t until about a year ago that I noticed any
effects. But over the past twelve months, I found myself frequently
having to remind people of tasks, mostly outstanding emails, across
the whole spectrum, and including companies who could make money
from me if only they d bother replying.
Statistics somewhere say that 90% or more of all mail is spam. I
have very few problems with spam (and would like to describe my
mail filter in a future post, but that ll take time), but I have no
problem imagining how most email users out there, who are stuck
with technology from the nineties (thanks mostly to Microsoft), are
really drowning and thus fail at the basics of correspondence.
So what s next? How should we continue to communicate, now that
email has been fully embraced by the business world while it has
grown to be more of a burden than a gain for the majority?
Or is our society simply accumulating more and more
slackers?
NP: