Will's Digital Garden

Speculative Programming Paradigm

As you may know, one of my dream programming environments is an evolution that pulls from notebook-style programming and spreadsheets, while remaining simple for new users.

An interesting paradigm that could be included in such an environment is a way of specifying randomness, possibilities, or ranges and having that information percolate through other operations. And on top of that, a built-in visualization of that percolated information. Ranges would be visualized similar to how they were input. Randomness might be visualized as a list of possible outcomes and the percentage chance of each occurring.

On the topic, here's a super rad implementation of a similar idea: Ambsheets, which gives the user of a spreadsheet the ability to specify multiple discrete options for any given value. I'd love to give Ambsheets a spin, but it isn't publicly available to use.

Ranges

Consider this excerpt of a fictional notebook-style programming language. It's a bit contrived, but the range of cost per ticket propagates through the multiplication operation into the result, showing a range of total cost.

# The cost of a ticket is somewhere between 15 and 20, inclusive.
cost_per_ticket = 15 ... 20

# We have 4 people in our group.
people_in_group = 4

# Without assigning this expression,
# the notebook interface just shows the resulting value in an inline comment.
cost_per_ticket * people_in_group # => 60 ... 80

Randomness

Similar to propagating ranges through other operations, we could have randomness do the same. Below, another contrived example: it shows what results would happen when rolling for damage in D&D and affecting an enemy's health at a glance. Without being able to play around in a sandbox environment with dice rolls easily, it's hard for me to imagine what kinds of outputs a user might find useful.

# Setup the enemy's current health
goblin_hp = 18

# Roll two six-sided dice and add the results
dice_results = Random(1, 6) + Random(1, 6)

# Store the enemy's new hp, after considering the damage from the dice
new_hp = goblin_hp - dice_results

# Without assigning this multi-line expression,
# the notebook interface would show the results in a comment below
if new_hp <= 0 {
  "dead"
} else if new_hp <= 9 {
  "bloodied"
} else {
  "a little damaged"
}
# => 0% chance of "dead"
# => 83.34% chance of "bloodied"
# => 16.67% chance of "a little damaged"