Testing in Elixir with Multiple Environments

About a year ago, I was learning how to properly unit test Phoenix applications using the Mox library. The strategy I adopted for my side projects involves adding “module dependencies” to any module I want to unit test, and then using Mox to configure those dependencies during the tests.

While that approach is great for preserving good unit test hygiene, such as using explicit intra-module contracts, it isn’t always the simplest. One major hurdle I’ve encountered since writing that post is figuring out how to use both unit and integration tests in a sane way. Read more on Testing in Elixir with Multiple Environments…

Folding Away Mutations in F#

I’ve been working in F# lately, and one of its smaller features has had a big impact on my programming style: Variables are immutable by default. If you want to change something, you have to declare it mutable. Sometimes, this is what I naturally reach for, and the language rubs my nose in it.

Here’s a story of one of those instances, and a new pattern I’ve picked up as a result. Read more on Folding Away Mutations in F#…

An Introduction to Property-Based Testing with JavaScript

Property-based testing is a powerful technique that’s been widely and successfully applied to functional-style codebases for a long time. As functional programming continues to get more and more popular among JavaScript developers, the value of this style of testing is becoming more obvious to a wider audience. Read more on An Introduction to Property-Based Testing with JavaScript…

A Simpler Case for Functional Programming & “Elegant” Code

A lot has been written about the benefits of functional programming, but little of it is accessible to a newcomer. Some of the benefits are easy to understand from an inexperienced perspective (e.g. “it makes concurrency easier”), but others are pretty nebulous.

Chief amongst the inscrutable properties of functional programming is its “elegance.” It isn’t immediately clear what that word actually means in this context. Read more on A Simpler Case for Functional Programming & “Elegant” Code…

Using Decorators to Declaratively Extend Functions

The decorator pattern gained fame in the object-oriented world after being featured in the classic 1994 Gang of Four book, Design Patterns. Since then, it’s been used extensively in traditional object-oriented programming as an alternative to inheritance. What’s really going on behind the scenes though, is composition, which means decorators are also great for cleaning up some functional programming boilerplate.

We’re going to look at decorators in JavaScript, along with some proposed syntax sugar coming in ES2017 that will make it easier to use them. Read more on Using Decorators to Declaratively Extend Functions…

Building Better Board Games with Clojure and Gorilla REPL

A while back, my six-year-old daughter and I were on one of our regular daddy-daughter date nights when we decided to create a board game. We sat at a restaurant table with paper, crayons, and a small collection of Dungeons and Dragons trinkets. To my surprise, we built a fun little game that my daughter named Turtle Burglars.
Read more on Building Better Board Games with Clojure and Gorilla REPL…

4 Tips for Thinking Functionally

I’ve written before about why I prefer a functional programming paradigm to an object-oriented one, but it’s taken a long time to get there. I dabbled on and off for half a decade before the core ideas behind Clojure and Haskell really sank in and I could write code in my head without having to sit at a computer.

My relationship with functional programming may have been slow, but it was punctuated by several key insights. These deeply altered my approach to designing code, even code in non-functional programming languages.

Here are four habits that dramatically shifted my thinking toward functional programming.
Read more on 4 Tips for Thinking Functionally…

TDD in a REPL

REPLs (Read-Eval-Print-Loops) are often billed as a great place to experiment and learn a language or a framework. They provide a very tight feedback loop. However, it can be difficult or time-consuming to extract the knowledge gained from a REPL and include it in your source code. I’ve hit the up arrow many times in Ruby’s pry, trying to find the specific input I wanted to copy. And don’t get me started on dealing with multi-line input. Thankfully, the developers behind F# came up with a clever way of dealing with this problem. Read more on TDD in a REPL…