Rewriting software from scratch, a lesson learned from Mac OSX 10.10.4’s discoveryd

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, July 05, 2015

Follow me on Twitter as @mattiasgeniar

I’ve been struggling with slow logins when on an active directory domain on my Mac. I’ve tried pretty much everything, but nothing really seems to solve it permanently. I’ve sort of become accustomed to the problem, accepting it as-is.

But I’m hoping the Mac OSX 10.10.4 update that was just released will resolve this for me, at last.

Most of the internet agrees that the introduction of discoveryd in Mac OSX has been a failure. It was meant to replace a very old DNS resolving tool called mDNSResponder, but it never lived up to the expectation.

As a Mac user, I had never experienced problems with the “old” mDNSResponder. There may have been a few edge-cases I was unaware of, sure. But to me, it just seemed to work. Before Mac OSX 10.10, I never experienced any of the declining software quality concerns others had raised.

Now enter Mac OSX 10.10. Apple completely rewrote the mDNSResponder and replaced it with discoveryd. From the ground up.

Here’s a processlist of Mac OSX 10.10.3.

$  ps -ef | grep discoveryd
   65    74  Fri10am /usr/libexec/discoveryd --udsocket standard --loglevel Basic --logclass Everything --logto asl
    0   274  Fri10am /usr/libexec/discoveryd_helper --loglevel Detailed --logclass Everything --logto asl

Before 10.10, and now back with the release of 10.10.4, mDNSResolver is running.

$ ps -ef | grep mDNS
   65    91     1   0 12:43pm ??         0:00.44 /usr/sbin/mDNSResponder

Ars Technica has a pretty good summary of the supposed reasons for the rewrite and the gotcha’s, this in particular.

As of OS X 10.10, mDNSResponder has been replaced by discoveryd. Curiously, discoveryd is (re)written in C++, not exactly one of Apple’s favorite languages.


Why DNS in OS X 10.10 is broken, and what you can do to fix it

Apple’s move here deserves a repeat of what Joel on Software has been preaching for a very long time.

There’s a subtle reason that programmers always want to throw away the code and start over. The reason is that they think the old code is a mess. And here is the interesting observation: they are probably wrong. The reason that they think the old code is a mess is because of a cardinal, fundamental law of programming:

It’s harder to read code than to write it.

Things You Should Never Do, Part I

Since to the outside world, there didn’t seem to be any reason to replace mDNSResponder, the move must have come from the inside. Engineers wanting to replace ageing software with something new.

In particular, Joel’s 15 year old blogpost (!!) notes that rewriting software always destroys some of the gathered knowledge: years of bug fixing and feature adding.

When you throw away code and start from scratch, you are throwing away all that knowledge. All those collected bug fixes. Years of programming work.

There are very legit reasons to rewrite software as well. But whenever I’m thinking of rewriting something from scratch, I hope I remember Joel’s words and Apple’s fiasco.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.