Michael Mentele Software Engineer

Use Wishes to Solve Programming Problems

Dandelion seeds blowing in the wind

Code is hard. Sometimes problems just seem like too much and you don’t know where to start. The complexity is overwhelming or the topic is just too new.

Make a wish I say–make a wish!

Not upon a star or to your fairy god mother; no, instead make wishes on abstractions.

The Wishlist

The idea is simple, when you have a problem statement; write a highlevel list of functions you wish you had to solve the problem for you.

These are declarative abstractions that will solve your problem. As part of making some cool data pipeline, in step 2 you need to turn widgets into whatchits instead of getting hung up on implementing that, you ‘declare’ that there is this black box that crunches widgets into whatchits.

This allows you to reason at ONE layer of abstraction and drive to a solution layer by layer.

Let’s say I had to write a program that would run the matrix. Now, I have no idea how to code the Matrix but I can probably break it into a abstractions I wish existed and pretend some other smart guy would write them.

It might be like:

    while (matrixExists()) {
        updateEnvironment(); // I have no idea how to write this code

Now, right now I’ve just broken the problem into two problems by ‘wishing’ I had a function that could handle the environment object and handle the people objects–the agents might do their own separate thing and interact with the environment through events. Again, no clue. The important thing is the problem space just got cut in half.

Alright, now we do the same thing for our updateEnvironment function. What does this funciton even do? Well, it handles all the things not having to do with people. So things like buildings, weather, temperature of rooms and places, the night sky, physics etc.

We are assuming the matrix isn’t deterministic and that people will basically need event handlers for all of their actions. So the environment is a purely reactive environment.

function updateEnvironment() {
    handlePhysics() // tracks the status of all molecules
    // The list goes on... how did those computers do it?

Great, now we write a wishlist for handlePhysics(), and then… You guessed it! We do it again and again until we get to a problem we know how to solve.

From handlePhysics we might drill down to a function like:

function computeForce(mass, acceleration) {
  mass * acceleration

That’s it! This is a recursive problem decomposition algorithm. Start at the top, your high level ‘wishlist’ and keep going until you find something simple enough you can solve.

Now, go create the matrix!