Stories and programming

Over at, someone left a comment that it would be cool to write a program in the form of a story.

This is both easier and more difficult than it sounds.

It’s easy because you can just make a bunch of text strings that tell a story, and hard code it into a “program” and, Shazaam! You’re done! This kind of feels like cheating, and doesn’t really impose the restrictions that one would expect from “writing a computer program”

It is also difficult, because if you want the program to actually do something, there’s a fairly strict syntax that you have to follow. Especially for compiled languages, there are lots of pieces that all need to be in the right place. This makes forming a narrative (especially one NOT centered around logical operators) extremely difficult.

But hey! Why not give it a try? Here’s my attempt at a story written as a computer program, written in Python 3.2 (a fairly forgiving language) with the added bonus that the story prints out its own ending on execution.

Once_upon_a_time = "there was"
a = {"boy":"named"}
def who(met, a_troupe_of, jugglers, performing_in, the_street):
    one_was_a = "robot"
    one_was_an = "alien"
    and_one_was_a = "man"
    the = jugglers
    danced_about = the_street
    tossing = "knives_over_everyone"
    they = met
    they[danced_about] = the
    boy = "and said"
to = "your parents"
a["smile"] = "crossed the boy's face, and he said"
are = {"you":"joking? my father is right here."}
_is = {"this":"true"}
the = "man asked"
who(_is, "your", "father", "the_robot", "asked")
the_boy_named_def = input
He = "is right there"
into = "the robots keypad"
answer = "when"
this = _is["asked"]
the = "alien responded, or you will"
_be = "sorry"
then = "the man "
raised = "his eyebrows, and"
said = then + "is my "
son = "finally returned?"
the_boy_named_def(said + this)

When executed, the program prints “the man is my father”

As you can see, I took the middle road and chose to make it readable if you ignore all the control characters (brackets and = and + and stuff) and add your own punctuation. It’s a fairly poor story, and even worse programming, but I hope you enjoyed it anyhow! And, if you found it too difficult to read in the program form, here it is in normally formatted English.

Once upon a time, there was a boy named “def” who met a troupe of jugglers performing in the street. One was a robot, one was an alien, and one was a man. The jugglers danced about the street, tossing knives over everyone they met.
They danced about the boy and said, “Return to your parents!”
A smile crossed the boy’s face, and he said, “Are you joking? My father is right here.”
“Is this true?” the man asked.
“Who is your father?” the robot asked.
The boy named def input “He is right there” into the robot’s keypad.
“Answer when this is asked,” the alien responded, “or you will be sorry!”
Then the man raised his eyebrows, and said, “then is my son finally returned?”
The boy named def said this, “the man is my father.”

About Ziggy

I strive to be awesome for God. Support my efforts at:
This entry was posted in Articles, Other, Short Stories and tagged , . Bookmark the permalink.

One Response to Stories and programming

  1. Leah and Charlette says:

    I like stories, but I don’t know about programming.

Leave a Reply

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