If Authors Wrote Stories the Way Programmers Write Code

There is a saying in coding circles that code should read like well-written prose. While on the surface this sounds like an admirable goal, we’re actually taught to break down our code, which can lead to it being hard to follow and understand if done to too fine a detail. Its interesting to compare that sort of writing to actual prose.

The following is a made up example of the other way around: what prose would look like if written like typical code. The main point of this is that code readability is something worth thinking about – and that maybe the automatic decomposition of code into smaller and smaller units may not always be the best thing to do, especially if we are interested in having the code be able to be easily understood. At some point, we begin to lose a lot of the context and coherence that allows us to maintain it properly in our minds.

I don’t really have hard-and-fast rules for when to break down or not, but it’s something I have been keeping firmly in mind when writing code lately. I think it’s worth thinking about and exploring in different ways to see what actually works best.

The story is “Goldilocks and the Three Bears”, with text taken from this website: https://www.wardleyce.co.uk/serve_file/699125

I fixed one error in the text and normalized some of it to keep the code from getting too special-case. There may actually be bugs in this, as it’s not something that can actually be run.

Enjoy!

=================================================================

{Story}         # Execute the story!

define Story:
    {Intro}
    {Girl_Enters}
    {Girl_Food}
    {Girl_Chairs}
    {Girl_Beds}
    {Bears_Enter}
    {Bears_Food}
    {Bears_Chairs}
    {Bears_Bed}
    {Girl_Exits}

constant Girl: "Goldilocks"
constant Food: "porridge"

constant Just_Right: "just right."

constant Daddy_Size: "big"
constant Daddy_Bowl_Size: "large"  # fix this inconsistency?
constant Mummy_Size: "medium"
constant Baby_Size: "small"

thing Daddy_Bear: [
    name: "Daddy Bear",
    bowl_size: Daddy_Bowl_Size,
    food_state: "too salty!",
    chair_size: Daddy_Size,
    chair_state: "too big!",
    bed_size: Daddy_Size,
    bed_state: "too hard!"
]

thing Mummy_Bear: [
    name: "Mummy Bear",
    bowl_size: Mummy_Size,
    food_state: "too sweet!",
    chair_size: Mummy_Size,
    chair_state: "too big, too!",
    bed_size: Mummy_Size,
    bed_state: "too soft!"
]

thing Baby_Bear: [
    name: "Baby Bear",
    bowl_size: Baby_Size,
    food_state: Just_Right,
    chair_size: Baby_Size,
    chair_state: Just_Right,
    bed_size: Baby_Size,
    bed_state: Just_Right
]

define Eating_My_Food:
    Someone's been eating my {Food}

define Sitting_In_My_Chair:
    Someone's been sitting in my chair

define Sleeping_In_My_Bed:
    Someone's been sleeping in my bed

define Intro:
    Once upon a time there lived three bears and a little girl called {Girl}.

define Girl_Enters:
    One day, she saw a house and went inside.
    {{break}}

define Girl_Porridge: 
    She saw some {Food}.
    {{break}}
    {Tasted_Bowl_And_Commented(Daddy_Bear)}
    {Tasted_Bowl_And_Commented(Mummy_Bear)}
    {Tasted_Bowl_And_Commented(Baby_Bear)} She ate it all up.
    {{break}}

define Girl_Chairs:
    {Girl} saw three chairs.
    {{break}}
    {Sat_In_Chair(Daddy_Bear.chair_size)}. “{Chair_Is(Daddy_Bear.chair_state)}” she said.
    {Sat_In_Chair(Mummy_Bear.chair_size)}. “{Chair_Is(Mummy_Bear.chair_state)}” she said.
    {Sat_In_Chair(Baby_Bear.chair_size)} and said, “{Chair_Is(Baby_Bear.chair_state)}” Then it broke.
    {{break}}

define Girl_Beds:
    {Girl} went upstairs.
    {{break}}
    {Lay_Down_On_Bed(Daddy_Bear)}
    {Lay_Down_On_Bed(Mummy_Bear)}
    {Lay_Down_On_Bed(Baby_Bear)} She fell asleep.
    {{break}}

define Bears_Enter:
    The Three Bears came home.
    {{break}}

define Bears_Porridge:
    {Bear_Scene({Eating_My_Food}, "it's all gone")}

define Bears_Chairs:
    {Bear_Scene({Sitting_In_My_Chair}, "it's broken")}

define Bears_Beds:
    They went upstairs.
    {{break}}
    {Bear_Scene({Sleeping_In_My_Bed}, "she's still there")}

define Girl_Exits:
    {Girl} woke up and screamed. She ran away and never went back into the woods again.

define Tasted_Bowl_And_Commented(bear):
    {Tasted_Bowl(bear.bowl_size)} and {Said_Food_Is(bear.food_state)}

define Tasted_Bowl(size):
    She tasted the {size} bowl

define Said_Food_Is(food_state):
    said, “This {food} is {food_state}”

define Sat_In_Chair(chair_size):
    She sat in the {chair_size} chair

define Chair_Is(chair_state):
    This chair is {chair_state}

define Lay_Down_On_Bed(bear):
    She lay down on the {bear.bed_size} bed and said, “This bed is {bear.bed_state}”

define Bear_Scene(each_said, baby_added):
    “{each_said},” said {Daddy_Bear.name}.
    “{each_said},” said {Mummy_Bear.name}.
    “{each_said}, and {baby_added}!” cried {Baby_Bear.name}.
    {{break}}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.