Metaprogramming With Lists in Clojure

Generating methods based on the content of arrays, hashes, and other Enumerable things is a powerful metaprogramming technique in Ruby. To keep things relatively simple, let’s use an example problem from Katrina Owen’s fantastic site Exercism: Write a program that, given an age in seconds, calculates how old someone is in terms of a given planet’s solar years. We know the length of an Earth year in seconds and the length of every other planet’s orbital period in terms of earth years.

Better Tests Through Metaprogramming

Duplication causes all of the same maintainability issues in test suites it does in production code, but I often see the DRY principle violated in the name of comprehensive test coverage and fidelity. Let’s say we have a Rectangle class that normalizes a range of inputs and we want to test all of them. How can we accomplish this without: Writing an individual test for each input (duplication)? Writing one test with multiple assertions (lost fidelity)?

Destructuring in Ruby and Clojure

As a long time Rubyist who picked up Clojure earlier this year, I have noticed the following pattern repeats itself: Encounter some new concept in Clojure Become confused by said concept and spin my wheels for a bit Realize I was using this concept in Ruby without knowing its name and full potential Simultaneously level up Ruby and Clojure skills Destructuring is the perfect example of one such concept.