Sam Gentle.com

Most constrained and least constraining

I've been thinking a bit about software design, decisions and, for certain reasons, puzzles. One thing that's difficult to explain is how to make good decisions when designing software, or how to choose between one implementation strategy and another. Like many decision-making processes, it's full of heuristics that are hard to explain, but thanks to the indomitable efforts of AI researchers, some of them have already been described for us.

Constraint Satisfaction Problems, where you simultaneously try to satisfy a bunch of different requirements by changing values around, are a particularly relevant field of research. They mostly involve situations that are too complex to have closed-form mathematical solutions, and too large in scale to simply brute force your way through. Instead, you have to get a bit clever with how you choose which values to try first. In other words, you use heuristics.

Two important but simple heuristics are called most constrained and least constraining. That is, you pick the variable with the least options, and you set it to the value that leaves the most options for other values. These two heuristics together can produce a surprising improvement, even with an otherwise naive algorithm. The reason they work is the variable with the least options is going to be the hardest to satisfy, and the value for that variable that leaves the most options is going to give us the highest chance of success.

I think those heuristics are equally important in software design. You want to start with the biggest, hardest requirements first, because once you've got them out of the way everything else gets easier. But you also want to take care to try to solve those requirements in a way that takes the fewest decisions off the table for the rest of your code. I don't mean that you should write everything in a super-overly-abstract way, just that you should avoid doing things in a way that cuts off options unnecessarily. You can be flexible by doing less, which is preferable to being flexible by doing more.

There are some interesting implications about decisions beyond software, too. It's not unreasonable to view your life as a very complex Constraint Satisfaction Problem. If that's the case, it could be worth thinking about which decisions are the most limited, and whether you're making those decisions in a way that maximises your remaining options.