What I Learned Approching Idris With An Agenda

A few years ago I wrote up a little Scala library for dealing with dimensioned units of measure. This had two implementations. One was type-safe, but required defining all the combinations of dimensions and the operators to yield them manually. One was dynamic, determining the dimensions of a given quantity based on the dimensions of … More What I Learned Approching Idris With An Agenda

How To Find Bugs, Part 4: Design -> Analysis -> Design

At LMAX, we have a bit of a case of primitive obsession. Many datatypes are represented internally with longs: prices and quantities (in a fixed-point representation), contract sizes, and IDs for more or less everything (customers, instruments, all sorts of things). This is a deliberate tradeoff: while we understand the benefits of a richer set … More How To Find Bugs, Part 4: Design -> Analysis -> Design

How To Find Bugs, Part 3: @VisibleForTesting

Sometimes, doing things properly is hard. When that happens, there’s always @VisibleForTesting. To quote the Javadoc: @VisibleForTesting annotates a program element that exists, or is more widely visible than otherwise necessary, only for use in test code. There are occasions where @VisibleForTesting is the best solution, I suspect: I’m not entirely sure what they are. … More How To Find Bugs, Part 3: @VisibleForTesting

How To Find Bugs, Part 2: Well, this is somewhat confusing and frustrating

Last time we implemented a minimal detector, and I presented the code for the detector as a fait accompli. Let’s take a closer look at it.   import java.nio.file.Files; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.classfile.ClassDescriptor; import edu.umd.cs.findbugs.classfile.DescriptorFactory; import edu.umd.cs.findbugs.classfile.MethodDescriptor; public class FilesLinesDetector extends BytecodeScanningDetector { private static final ClassDescriptor JAVA_NIO_FILES = DescriptorFactory.createClassDescriptor(Files.class); final … More How To Find Bugs, Part 2: Well, this is somewhat confusing and frustrating

How To Find Bugs, Part 1: A Minimal Bug Detector

Findbugs is an incredibly powerful tool, and it supports running of custom detectors. However, the API for writing custom detectors is not well documented, at least as far as I’ve been able to find. So, as I started writing detectors, I’ve been working primarily off a process of trial and error. It’s likely there are … More How To Find Bugs, Part 1: A Minimal Bug Detector

Yet Another Python Multimethod Decorator, Part 6: But Wait, There’s More!

Somehow this ended up unposted and thus out-of-order, bah… So, we’ve now got a reasonably complete implementation of multi-methods for Python. I can feel some objections brewing in the minds of some readers – aspects of a “proper” multiple dispatch mechanism that I haven’t addressed here – but hush, there are some points I’ll arrive … More Yet Another Python Multimethod Decorator, Part 6: But Wait, There’s More!

Yet Another Python Multimethod Decorator, Part 7: What You’re Trying To Do Is Wrong

One of the recurring difficulties with multimethods is the concept of method resolution order. If you have multiple methods with the same name but different parameter types in scope, and you call the method with types such that more than one method which can accept them, how do you decide which one to dispatch to? … More Yet Another Python Multimethod Decorator, Part 7: What You’re Trying To Do Is Wrong

Yet Another Python Multimethod Decorator, Part 5: Duckfaces

OK, so our multimethod decorator is progressing nicely. It’s robust and versatile in ways it wasn’t before, handling a whole bunch of common situations sensibly in a way our starting point didn’t. Let’s do something with it that might actually seem reasonable to want to do. flatten is a simple function which takes a list, … More Yet Another Python Multimethod Decorator, Part 5: Duckfaces

Yet Another Python Multimethod Decorator, Part 4: What about subclasses?

So, now our multimethod decorator produces things which actually behave like a function – it follows sensible scoping rules, and binds properly so it can be used as a method. That shouldn’t be a high bar, but there you go. Now let’s look at how we might use it. I’m clearly writing this the wrong … More Yet Another Python Multimethod Decorator, Part 4: What about subclasses?