Jason Garber

Tracking innovations in code and culture

Video of My Talk on Writing DSLs With Parslet

The video of my talk from Wicked Good Ruby Conf in Boston is online.

A well-designed DSL improves programmer productivity and communication with domain experts. The Ruby community has produced a number of very popular external DSLs—Coffeescript, HAML, SASS, and Cucumber to name a few.

Parslet makes it easy to write these kinds of DSLs in pure Ruby. In this talk you’ll learn the basics, feel out the limitations of several approaches and find some common solutions. In no time, you’ll have the power to make a great new DSL, slurp in obscure file formats, modify or fork other people’s grammars (like Gherkin, TOML, or JSON), or even write your own programming language!

It is is licensed under Creative Commons Attribution ShareAlike 3.0. I owe a big thank-you to Confreaks and Wicked Good Ruby Conf for making it available online.

Video of Conference Talk on Small-Time Automated Server Provisioning

The video of my talk at Madison Ruby is online. Automated infrastructure is intimidating but very important, so I encourage conference attendees to dip their toe in the water with a simpler subset of the Chef stack.

Chef is a great tool for managing a vast and complicated server infrastructure, but what if you have fewer servers than fingers? What if you just want a simple little box to host a Rack app? Maybe a staging server to match or a CI server? With little or no prior knowledge of Chef, you can set up a server fairly quickly if you know the right way to set up your kitchen. (They don’t make it obvious. I’ve lost a few fingers in the process.) We’ll walk through the basics of Vagrant, Chef-solo, Knife-solo, using community cookbooks, and writing your own simple cookbooks.

It is is licensed under Creative Commons Attribution ShareAlike 3.0. I owe a big thank-you to Confreaks and Madison Ruby for making it available online.

Slides From Writing DSLs With Parslet at Wicked Good Ruby Conference

A well-designed DSL improves programmer productivity and communication with domain experts. The Ruby community has produced a number of very popular external DSLs—Coffeescript, HAML, SASS, and Cucumber to name a few.

Parslet makes it easy to write these kinds of DSLs in pure Ruby. In this talk you’ll learn the basics, feel out the limitations of several approaches and find some common solutions. In no time, you’ll have the power to make a great new DSL, slurp in obscure file formats, modify or fork other people’s grammars (like Gherkin, TOML, or JSON), or even write your own programming language!

Announcing PromptWorks

I’ve joined Mike Nicholaides and Greg Sterndale to form a new consultancy:

PromptWorks

PromptWorks is the premier Philadelphia software consulting shop, specializing in Ruby, JavaScript and related technologies. With a collective 30 years of software experience, we are industry veterans with unmatched technical chops. In addition to helping businesses build new web apps and APIs, we solve problems with existing apps like scaling, testing and automating development operations.

Thief Card Game

My extended family has been playing a card game called Thief for the past several years. It’s been passed along orally through the network of grandparents and retirees, but we cousins have really enjoyed playing it too! The stealing element is what makes it so competetive and fun. Trash talk is a key feature of the game.

I can’t find the rules anywhere on the Web, so I asked my mom to write them down. Reply in the comments with questions or corrections to the rules. If you know this game by another name, I’d love to know and have some official rules to consult.

Ruby Programming Style and Your Brain

Last week someone was looking over my shoulder as I typed a command to run a script. It was something mundane, like ./script/test. He said, “you know, you don’t have to type the dot slash,” and I thought, “Wow, he’s right; I’ve been typing those extra characters for years!”

Just a little later, I ran a different command in the script directory and this time I didn’t use the dot slash. sc Tab ↹

SCREEN_NO        scandeps.pl      schemagen        script         
sc               scandeps5.12.pl  scp              scselect       
sc_auth          sccmap           screen           scss           
sc_usage         sched            screencapture    scutil 

Oh, right! Tab completion works much better with just the tiniest bit of context, so if I use the dot slash and script is the only thing in that directory that starts with sc, I end up typing the whole command faster. Of course, by the time I realized this there was no longer someone looking over my shoulder!

We programmers develop a million of these little tricks over the years and often don’t realize it when we do. At least I wasn’t aware enough at that particular moment to explain to my backseat driver why the dot slash flew off my fingers. Maybe I didn’t even come up with that trick on my own. Sometimes we inherit best practices from others’ experience.

Ruby coding style is no exception. You don’t have to parenthesize your arguments when you call a method, but if you usually don’t, there will be some times when you do—method chaining, for instance—and you’ll have to go back and put them in. Or consider why we prefer || to or and && to and. You can use or and and, but you have to keep the order of operations in your head, and that’s one more thing to keep track of. && is generally the operator prescedence that you’re intending.

Douglas Crockford talks about Javascript Programming Style (got to love the bit at 13:34!) and how there are some things the language allows that you just shouldn’t do. Though Ruby is a better-designed language and there are fewer dark, spooky corners than Javascript, there are best practices that will keep you out of trouble, or at least be more efficient and make changing the code easier. Thus, a canonical Ruby style has emerged over the last half-decade and, though there are variations here and there, it’s pretty much this: GitHub’s Ruby Style Guide

That’s not to say GitHub sets the standard for Ruby development. They just forked Bozhidar Batsov’s style guide, and he developed it out of his experience, various Ruby books, and no doubt reading thousands of programs over his career. If you had a thousand Ruby coders write style guides and then averaged them, I’d wager it would be very close to GitHub’s.

I don’t know that we need a Ruby Lint analysis program like Javascript has. The pitfalls are less precipitous and you’re test-driving your code anyway, right? Still, hat tip to Codegram for Pelusa. For me, embodying the canonical style is good enough. Just be aware of why each element of this style is better than the alternatives so you can defend and maintain the cohesive style that we’ve worked so hard to develop.

Having a backseat driver isn’t all bad. I did a cd .. followed by cd that-same-directory to pick up some automatic per-directory settings (RVM, probably) and he suggested cd . instead. Great! An obviously possible combination, but something that han never occurred to me. Even spectator programming (as opposed to pair programming, which has been rocking my socks all year) has its advantages.

Pair Programming When You Type on Different Keyboard Layouts

At work we’re often pair programming and we have the ideal pairing rig, but one thing wasn’t ideal: I’m the only one who types on the Dvorak keyboard layout.

Pairing with two different keyboard layouts means you have to switch input modes a lot. Usually it involves a little bewilderment as vim scrambles your code before you remember that you’re in the wrong mode.

I hated that my choice of keyboard layout was a burden on my pairing partners, so eventually I found a software solution: KeyRemap4MacBook

I’ve dropped Dvorak-Qwerty ⌘, which is broken, and now just use the Dvorak input source with KeyRemap4MacBook converting my ⌘ keypresses.

I also made one of the keyboards at each pairing station “mine” and then set KeyRemap4MacBook to convert the Qwerty keypresses of the others to Dvorak, but only when my computer is in Dvorak input mode.

KeyRemap4MacBook Fixes the Broken 'Dvorak - Qwerty ⌘' Layout

I switched to the Dvorak keyboard layout over Christmas break in 2001, figuring that if I were to spend the next 80 years typing, a couple weeks re-learning to touch type would be worth it.

And it has been. My hands just never get tired of typing, which is good because I spend all day at it. There are only two problems with being in the minority on this:

  1. Shortcut keys are less convenient to use. Cut, copy, and paste are X, C, and V for a reason. You can get used to the new positions, but they never quite feel as handy.
  2. Sharing or borrowing other computers becomes more difficult.

Connecting to HipChat From IRC

My friends at IndyHall are always talking on HipChat, but I too often forget to open HipChat in my browser and I’m not interested in running their Adobe AIR app. I have been on IRC a lot lately thanks to the Philly Ruby community, so getting my IndyHall hipchats on IRC has been an itch I’ve needed to scratch for awhile.