RC W1D4 - Domain-specific software (sketch)

OK we’re back on to 'sharing sketches of my blog post ideas along the way’, here we go.

When I think about CS topics, I think about operating systems, databases, networking etc. These are domain-agnostic. I began to ponder, are there specific aspects of a language, framework or paradigm that’s particularly useful for working in a specific domain (finance, healthcare, education etc)? What choices would you make based on what you’re optimizing for? Is domain-specific software a thing?

SICP touches on this at the start of Chapter 3:

One powerful design strategy, which is particularly appropriate to the construction of programs for modeling physical systems, is to base the structure of our programs on the structure of the system being modeled.

This preface led to a discussion of mutability and functional vs imperative models. A related idea is the argument that the functional model allows us to focus on the domain, and not the step-by-step execution.

I had a coffee chat with Jacquin Mininger which led to a number of threads and resources, as sketched out below. I’ll likely finesse these once I’ve done a bit more homework. Mistakes my own.

Types - With strong types, we’re able to constrain the space of illegal states (since we can’t use a function that operates on strings to work on integers, say). With static types, we are able to run these checks at compile time. With an expressive type system, you can even say represent a EUR/USD pair with its own type instead of a float, so it’s not possible to mistake this for a GBP/USD pair (I believe this example is from here, which I need to re-read).

Pure functions - When you don’t have side effects, your code is easier to understand because its impact is isolated. It also makes refactoring easier. A thought that came up here is Jane St being a fan of OCaml. While the functional aspect is a plus, it's easy to overlook how it’s an even bigger plus when it’s both the functional and types working together to maximize how much the domain can be ‘expressed' in code.

Proofs - These provide an even stronger check. Agda and Coq are popular choices, but can be slow. Haskell is faster. Rust is even faster and has a much larger supporting ecosystem.

Math - There are some domains like crypto where the desired behavior is expressed in math, which also translates more naturally into Haskel.

Performance - It’s easier to reason about performance when using imperative languages because it’s closer to what the processor is doing. This means that it’s harder to do or less natural when using a functional language. It’s also easier to reason about performance when you don’t have to worry about the garbage collector ’stopping the world’; here Rust having no runtime can fare better vs Go.

Haskell - Related to the performance point above, this also means that you’ll need to know the compiler / GHC well to figure out where your bottlenecks are when writing Haskell.

Finance and crypto - The 'return on investment’ of using functional languages may be higher here given the emphasis on correctness. While this may weigh the choice towards correctness over performance, there are subdomains like high-frequency trading where you shouldn't be in business if you don't have performance.

Other domains - I have very little context if domain-specific software is a thing outside of finance and crypto, naturally would love to hear thoughts. I only also have the one example of Nubank acquiring Cognitech / Clojure, which anecdotally stresses the finance example.