Four things you should know about Rules as Code

1 Like

This is unrelated to the main subject of this forum, but I’d love to hear what @kemitchell has to say about it.

I’ve been daydreaming about programmable law for a few years now.

What I have seen, this article cites

France was one of the earliest adopters of this approach. They created an open source tool called OpenFisca to convert benefits and tax legislation into code.

as an example, is that “law as code” has only made sense and successfully tried in areas that require little to no interpretation of facts (So taxes / fiscal codes where everything is “per-categorized” so to speak and then can be interpreted along all the lines) and where existing complexity is too high already for even law-fluent people to struggle without tooling.

The other example I know is the Dutch Tax Authority using JetBrains MPS (DSL builder)

Maybe in a couple of years tho Law as Code stuff will move to other areas?

(Disclaimer, I’m from a technical side with almost no law/policy/government experience)


@fabian, welcome! @lux, thanks! I have added both page and paper to my reading list.

A ton of the law is about what evidence you can use in court and how that evidence turns into “facts”. It’s a big part of what the legal system does, determining the vast majority of wins and losses. And the legal system itself “runs” on legal rules.

Even once “the facts” are decided, the law doesn’t necessarily apply deterministically. Rules will be reconsidered or interpreted to avoid results that conflict with the point of the law. Many legal “rules” frankly aren’t if-then-else kinds of decision trees, but lists of “factors” that structure a judgment call. The rules themselves are written in natural language, some have been on the books for years, and whole branches might not have been reached before. Which leads to the trial lawyers’ maxim:

When the facts are with you, hammer the facts. When the facts are against you, hammer the law.

At risk of mentioning something political, we have seen a bunch of lawsuits about the result of the 2020 presidential election fail, often attempting to get their way with legal briefs in the absence of evidence. Sometimes by focusing on narrow points of little-remarked election law. Sometimes by swinging wide with broad constitutional arguments.

Ever since Lessig made his “code is law” point, especially code people have been trying to pun on it in the other direction. By “code is law” Lessig meant that choices written into software also create rules that we live and work by. It didn’t follow at all that law can or should be reduced to code.

There are more “mechanistic”, we might say “legalistic”, areas of law. And legal systems themselves vary somewhat in their approach here. For a very long time the English system, from which US and other former colonies’ systems descend, was actually split in two, with what we’d now call hyper-legalistic “courts of law” dishing out decisions based very strictly on rules that could have lent themselves to coding, but “courts of equity” applying more impressionistic principles of justice. People who lost in the courts of law on what they thought a harsh or unjust decision could go to the courts of equity and sue for relief. These days, here in the USA, the two systems are fused into one.

I do think lawyers and lawmakers could do better at recognizing situations where they’re trying to express a rule that could be expressed in more formal terms and using the tools mathematics, computer science, and frankly just bureaucratic management generally. If-then algorithms, state machines, and formulas, but also tables, diagrams, and Gantt charts. These days, there’s nothing to stop, say, financial contracts for #includeing a spreadsheet for calculations.

You’ve done a great job of deflating my fantasies. :sweat_smile:

But I still can’t help but daydream of something as crazy as writing down law for different organizations as library code, and then having some sort of omniscient AI enforcing that law automatically.

And then I remember that we already live in a world with smart contracts and nothing major has changed.


“Constitution as a framework”.
“Procedurally-generated law”.

I wonder if crazy ideas like that could be explored in some sort of videogame . . .

“Hammurabi: The Game”

Write down laws as code, and watch your little lemmings act automatically, constrained by whatever laws you specify.
Perhaps such utopian nerd fantasies can only live within the safe confines of a sandbox.

With varying levels of difficulty, based on increasing levels of human depravity that you must legislate away. :smirk: