Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

A Darwinian Nightmare

It seemed to have stepped right out of the pages of a horror novel. The mutant shape-shifter struck without warning, defying a mere mortal's attempts to detect it. It seemed to distort the fabric of reality itself. And it was going to ruin my job interview.

We've all encountered this monster at some point. Like many classic monsters, it is our own creation. Every year it devastate projects worldwide. The fearsome mutation bug is an expert at hiding and altering your programs in subtle and unexpected ways.

It doesn't have to be this way. Join us on a journey from monster-fearer to monster-tamer.

Details

I'll be walking through a lot of common mutation pitfalls in Ruby including Hash/Array default constructors, mutating constants, and mutating code you don't own.

We'll look at alternatives, how to deal with existing code that mutates, how to deal with third-party libraries, how to debug mutation bugs, and when mutation is OK.

This is not a "FP in Ruby" talk but instead a pragmatic look at the places where we mutate unnecessarily, where they bite us, what the alternatives are, and how to mutate safely.

I have a lot of real-life examples of times mutation bit me to demo. Of particular interest:

  • The first time mutation bit me in a really bad way and completely ruined my project
  • The time a third-party gem mutated a constant and caused me multiple hours of confused debugging.

Pitch

Mutation bugs are some of the most common bugs in Ruby as well as some of the hardest to debug. Most of this pain is self-inflicted since Ruby provides us the tools to avoid most of them.

I've encountered this bug under countless forms in the wild and have plenty of anecdotes to share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment