Menu Sidebar

A late-night rant about OOP and parametric dispatch

Update: this post was the product of an exhausted mind, and as such it misused terms, wasn’t well backed-up, and was generally incoherent. I’m withdrawing it until such time as I can articulate these ideas a little more competently.

I’m leaving this note here just to explain the absence. Here, have a photo of a mountain view:


Matching hostnames with pcase in Elisp

I am not what you might call a “competent” Emacs Lisp programmer. More of a cargo-culter, really. But I’m trying to get better.

I create RubyTapas episodes across two different machines: “hazel”, my main development box, and “caroline”, my Windows video editing box. I needed to be able to recognize my synchronized episode directory on either machine, but the paths are different. So I wrote this:

This uses cond , the general-purpose conditional macro. It works, but it’s clunky. I keep repeating the string comparison code. As a Ruby programmer, I want something closer to Ruby’s pattern-matching case statement.

Today I read up on the pcase macro. It turns out it is both simpler and more powerful than I had realized. I haven’t used any of the power yet. But for this very trivial problem, it was as simple as replacing the equality tests with literal strings.

Easy, and nicer to look at!

Newer Posts
Older Posts

Virtuous Code

"The three virtues of a programmer: laziness, impatience, and hubris" — Larry Wall


News, notes, and commentary from Avdi, weekly-ish.

Books and Screencasts

RubyTapas Screencasts

RubyTapas Screencasts

Small plates of gourmet Ruby code.

Confident Ruby

Confident Ruby cover

32 Patterns for joyful coding.

The Making of

Confident Ruby cover

Watch me build an app in Sinatra and Rails

Objects on Rails

Objects on Rails

A developer notebook on applying classic Object-Oriented principles to Ruby on Rails projects.

Exceptional Ruby

Exceptional Ruby

The definitive guide to exceptions and failure handling in Ruby.