Practical Elegance

"Elegance is not a dispensable luxury." - Edsgar Dijkstra

The Polyglot’s Dilemma

If it hasn’t been clear up to now, I love Clojure. I wish I could write Clojure all day, every day. But Clojure isn’t my first language, and possibly not even the language I grok most completely.

I jump between programming languages all the time, and end up having to do the most jumping at work because I probably have at least a passing familiarity with the most languages for anyone on our team. And that’s fine.

What I want to ponder on here is the challenges of “speaking” multiple programming languages, learning new ones, and moving between them.

I started programming BASIC when I was about five years old. By the time I hit high school, I was running Linux and writing Perl, C, and Bash scripts (throw some sed and awk in there for good measure, though one wouldn’t call them “languages” as such).

Full disclosure: I have written some PHP. But as the illusory Bertolt Brecht in Cradle Will rock tells the playwright Marc Blitzstein, “Capitalism makes prostitutes of us all.”

Okay, back to programming…

Recovering from Clojure/conj

Whew. I just got back from Clojure/conj and boy, is my brain tired.

I’l be doing a more detailed and code-oriented post with Milt Reder on the Yet Analytics blog this week, but I need to do a brain dump beofre I brainsplode.

So, getting the fanboy stuff out of the way: I got to shake Rich Hickey’s hand and thank him for all the work that went into Clojure and Datomic, i.e., the stuff that made programming fun again for me. So that was fun. This was at the conference party at the Crime Museum, which was a joy and a wonderful place for a party.

But, the actual conj…

Emacs: Down The Rabbit Hole

So I wrote Welcome to The Dark Side: Switching to Emacs in response to a tweet, but as any of my co-workers will attest, it doesn’t take much to get me started on my Emacs workflow.

I feel like a religious convert… I miss those simple, unadorned Vim services but I’m floored by the majesty of the stained glass and altar dressings and ritual of the Church of Emacs.

So before the jump, in the spirit of “I’ll show you mine if you show me yours,” my .emacs.d.

An Unexpected Journey

I lived in my happy little Vim hobbit hole, smoking my pipe and enjoying my brandy. It was not a dirty hole, or a sandy hole, but a hobbit hole, which means comfort.

One day, a wizard visted me.

And that’s when things began to get weird…

Reify This!

On the way home this afternoon I was asked to explain Clojure’s reify macro, and apparently I did quite well, as an “Aha!” moment resulted. So I shall endeavour to explain reify here in the hope that such a moment might be available to others.

Reify derives from the Latin res, or “thing.” So reify fundamentally means “make a thing out of….

Protocols and Datatypes

Clojure protocols are similar to Java interfaces: They define a set of methods/functions purely by their signatures without providing implementation details. Declaring that a class implements an interface (in Java) or that a record implements a protocol (in Clojure) is a contract that specifies that the given class or record, in order to be valid, will provide concrete implementations of those methods/functions.

But sometimes we don’t need a reusable entity with reusable implementations that we can instantiate willy-nilly; sometimes we just need a thing that implements those methods.

In Java, anonymous inner classes can fulfill this purpose. In Clojure, we have reify.

That Nameless Thing

OK, it’s not really going to be nameless… let’s say we have a putative protocol as follows:

1
2
3
4
(defprotocol Foo
    (bar [this])
    (baz [this st])
    (quux [this x y]))

So if we were creating a new record, we might do:

1
2
3
4
5
(defrecord FooRecord
    Foo
    (bar [this] (println this))
    (baz [this st] (str this st))
    (quux [this x y] (str this (* x y))))

Which is perfect if we need to repeatedly instantiate a FooRecord that implements the Foo protocol. But sometimes we just need a Foo and be done with it. And so, Clojure gives us reify.

Welcome to The Dark Side: Switching to Emacs

I have to start this post by saying I’ve been a dogmatic Vim partisan since the 1990’s, when I started using vi on the Solaris and Irix boxen I had access to, and then on my own machines when I got started with Linux in 1994.

I flamed against Emacs on Usenet, called it all the epithets (Escape Meta Alt Ctrl Delete, Eight Megs And Constantly Swapping (8 megs was a lot then), Eventually Mangles All Computer Storage)… I couldn’t stand the chord keys and lack of modality.

Even once I got heavily into Lisp I still tried to stick with Vim, or tried LightTable, or Atom, or SublimeText. But then one day I hit a wall and Emacs (plus cider-mode and slime and a few other packages) was the obvious solution. Now I’m out there evangelizing Emacs (I’m writing this post in the Markdown major mode plus some helpful minor modes) and I figure I’d offer some advice for those looking to convert to the Church of Emacs.

St. Ignucius

Fear and Coding in Las Vegas

I’m sitting in the first session of the Code.org K-5 PD training workshop.

It’s my first time in Las Vegas. We went to In-N-Out Burger (required if I travel out west), and I hit a $2k jackpot on penny slots. Not bad. And now we’re getting an overview of the K-5 Code.org curriculum. It’s pretty exciting.

I learned to code when I was 5. Learning BASIC on a TI 99/4A. This is pretty much my first computer:

Have A Happy #Whyday with whynot

It’s August 19th, the day we remember why the lucky stiff’s poignant departure from the internet. ruby-jokes would hate to part with the Whyday tradition of hacking on something just for fun and releasing it into the wild.

So it’s with great ambivalence we announce whynot, a gem that does irresponsible things because… why not?

whynot is for when you really just don’t care. It started as a single monkey-patch to Kernel, called maybe. maybe takes a block, and may or may not yield the result. So for instance:

maybe
1
2
3
4
maybe do |x,y,z|
  x,y,z = 1,2,3
  x + y + z
end

About half the time, this will return 6. The other half, nil.

About three minutes after I pushed whynot to Github, Micah Gates added some kernel methods that allowed for a little more specificity: mostly, which will execute your code about 2/3 of the time, and occasionally, which has about a 1 in 5 chance of actually executing your code.

But wait, there’s more!

Just in time for the 0.0.4 release this afternoon, I decided sometimes, the truth doesn’t matter. Or, at least, you just don’t care. So I added meh. Sometimes true, sometimes false, whatever. When you really don’t care, just do this:

1
meh ? "I guess" : "Nah."

I really wanted to create a global value like true or false that was neither truthy nor falsey, but I’m not sure whether that’s possible, and I have a feeling it would require some C-extension hackery if it is.

Perhaps for a future release?

As always, pull requests are welcome, and use at your own risk.

On Comments And Moderation

I’ve always taken a hands-off approach to moderating comments, feeling that it was a form of censorship to restrict discussion even on my own blog. It’s worked pretty well; I feel like prior to yesterday, I’ve deleted less than three comments in the three years I’ve maintained this blog.

But yesterday’s post, I’m Telling :: Employer-Tattling and The Decline of Agency, brought in some of the nastiest of trolls, and I had to re-evaluate that policy. The post also got so many comments I was going crazy trying to weigh my anti-censorship views against comments that bordered on hate speech.

I’m Telling :: Employer-Tattling and The Decline of Agency

The other night Twitter was abuzz with controversy and drama, as per usual. One of those threads (which I’ll get to momentarily) invovled what I’ll refer to as “employer-tattling,” and Jon Soeder (laudably without drawing attention to the ongoing echo chamber), tweeted this:

He doesn’t mention which Twitter thread prompted this, but I have an educated guess.