Ultratestable Coding Style

Darn side-effecting programs. Programs that change things in the outside world are so darn useful, and such a pain to test.For every piece of code, there is another piece of code that answers the question, “How do I know that code works?” Sometimes that’s more work than the code itself — but there is hope. … Read moreUltratestable Coding Style

Declarative style in Java

The other day at work, we had this problem: Sort a sequence of rows, based on an input list of columns, where each column might be sorted ascending or descending, and each column might require a transformation first to get to something comparable. The function interface looks like this: Here is a concrete example where … Read moreDeclarative style in Java

Trains within trains

In Java, there are primitive types and there are objects. Often we want to work with everything as an object, so those primitives get boxed up into object wrappers.Ruby and Scala say, “That’s silly. Let everything be an object to begin with.” That keeps parameter-passing semantics and comparison and printing operations consistent. Yesterday while writing … Read moreTrains within trains

What FP taught me about OO: Liskov Substitution Principle explained

TL;DR – functional programming taught me that LSP is a special case of PLS: Principle of Least Surprise. One thing that bugs me while reading Java: I’m reading along, come to a method call, ctrl-click on the method name, and get a list of implementations of the interface. IntelliJ can’t tell me exactly what will … Read moreWhat FP taught me about OO: Liskov Substitution Principle explained

Twisting the rules of logic in our code

In philosophy, there are very few things that can’t be doubted. The basic laws of logic are among them. There’s one that seems completely obvious and indisputable to normal people: Law of Identity: Everything is identical to itself. In my audiobook, the professor is going on about how not only is this statement true in … Read moreTwisting the rules of logic in our code

From imperative to data flow to functional style

Functional style makes code more maintainable. How? One way makes processing into a flow of data with discrete steps. Another way separates flow from context, making the context swappable. This post illustrates both. We’ll go from an imperative style to a more and more functional style. Scala is a good language for this illustration, since … Read moreFrom imperative to data flow to functional style

Functors: What the funk for?

For all the programmers who don’t deeply grok the lambda calculus terminology — Say you are about to call a method on a container, and that container can give you something back of type Tweet. What you really want isn’t a Tweet, but some part of it, say Tweet.getId(). What if, instead of getting the Tweet … Read moreFunctors: What the funk for?