An Opening Example of Elm: building HTML by parsing parameters

I never enjoyed front-end development, until I found Elm. JavaScript with its `undefined`, its untyped functions, its widely scoped mutable variables. It’s like Play-Doh, it’s so malleable. And when I try to make a sculpture, the arms fall off. It takes a lot of skill to make Play-Doh look good. Then Richard talked me into …

Read moreAn Opening Example of Elm: building HTML by parsing parameters

Quick reference: monads and test.check generators

Combine monads with test.check generators to build them up out of smaller generators with dependencies: (require ‘[clojure.test.check.generators :as gen])(require ‘[clojure.algo.monads :as m])(m/defmonad gen-m   [m-bind gen/bind    m-result gen/return]) (def vector-and-elem  (m/domonad gen-m    [n (gen/choose 1 10)     v (gen/vector gen/int n)     e (gen/element v)]    [v, e])) (gen/sample vector-and-elem);; ([[0 0] 0]     [[0 -1 1 0 -1 0 -1 1] 0]   …

Read moreQuick reference: monads and test.check generators

Left to right, top to bottom

TL;DR – Clojure’s threading macro keeps code in a legible order, and it’s more extensible than methods. When we create methods in classes, we like that we’re grouping operations with related data. It’s a useful organizational scheme. There’s another reason to like methods: they put the code in an order that’s easy to read. In …

Read moreLeft to right, top to bottom

When OO and FP meet: returning the same type

In the left corner, we have Functional Programming. FP says, “Classes shall be immutable!” In the right corner, we have Object-Oriented programming. It says, “Classes shall be extendable!” The battlefield: define a method on the abstract class such that, when you call it, you get the same concrete class back. In Scala.Fight! Here comes the …

Read moreWhen OO and FP meet: returning the same type

Property-based testing of higher-order functions

Property-based testing and functional programming are friends, because they’re both motivated by Reasoning About Code. Functional programming is about keeping your functions data-in, data-out so that you can reason about them. Property-based testing is about expressing the conclusions of that reasoning as properties, then showing that they’re (probably) true by testing them with hundreds of …

Read moreProperty-based testing of higher-order functions