Tech Life It screams to be understood

Debugging Westworld

I inherited Eli’s code. He’d left for a start-up, and he’d written the import/export code for our application half done. He’d left in a hurry which meant I got a sixty-minute whiteboard session where he explained where he was at and where he was planning on going with his code. The whiteboard was pleasantly covered with method names and a lot of boxes and arrows and it seemed like an effective 60-minute meeting. When done, I felt confident I could finish the code.

Then I saw the code. His undocumented code. His spaghetti code.

It is a software engineering rite of passage to inherit and maintain a codebase that you did not write. If the original writer is a moderately good engineer operating against a well-defined engineering style and they have taken the time to document their code, it’s still an effort to parse and understand how a chunk of code works before you start to add your own.

Eli was not a good engineer, there was no style guide, and didn’t finish. But Eli did help me better appreciate Westworld.

Wait what?

DISCLAIMER: There are no season one Westworld spoilers in this piece, but you shouldn’t click on any links below. This piece does not assume you’ve seen the series, but it can’t hurt if you did. There is no code in this piece, either.

Westworld is an HBO series based on Michael Crichton’s 1973 movie of the same world. Like the movie, the series is about a futuristic Western-theme amusement park populated by “Hosts” who are lifelike androids. In this immense park, actual humans (“Guests”) show up for vacation, paying a huge amount of money to fulfill their no-holds-barred fantasy. This includes Guests nonchalantly gunning down the Hosts.

From the minds of Jonathan Nolan (Memento, The Dark Knight series, and Interstellar) and Lisa Joy (Burn Notice and Pushing Daisies), Westworld has complex depth. It is clear from the first episode that there are layers to the mysteries of Westworld. A torrential flood of theories appeared overnight after the first episode. With each subsequent episode, existing theories were refined while others were introduced. To date, I’ve spent three times as much time thinking and discussing Westworld versus watching it, and I’ve watched the series beginning to end twice. Perhaps a more compelling way to describe this act is I’ve been debugging Westworld.

There is a lot going on within Westworld. There’s what is going on in the park, there is what is going on with the administrators of the park, there’s a cast of characters who are androids who do not know what they are, there’s a cast of humans who treat the park like an amusement park, and there are those humans who believe the park is something else. Motivations are unclear, timelines are suspect, and so are narrators. Within a rich and complex set of narratives, there are constant reminders that there is more going on than meets the eye. Season 1 is written to be analyzed. It screams to be understood and to be debugged.

Attempting to debug Westworld is a similar act to understanding someone’s else undocumented code. The task begins by reading the code for the first time and beginning to build a mental model of how it works. The quality of the code greatly affects the difficulty of this task, and in the case of Eli’s code, this task was awful. Reading the code revealed no obvious model, and after a second read, I considered a complete rewrite. I didn’t have the time, and I also knew that all code obeys rules.

Eli’s code compiled, which meant it followed the basic rules. I could make basic guaranteed assumptions, so I began tinkering. What happens when I change this variable? Oh. What happens if this method is removed? Good to know. After many hours of deconstructing and reconstructing, I had a beginning model of how Eli’s code worked. It was still crap, but it was a bit more understood.

Here’s the process:

  • Read the code, which is based on rules.
  • Begin to build a mental model of how the code works.
  • Test the model.
  • Repeat until your model is sound.

In Westworld, the narrative is the code. It describes how that universe works, but as with any good narrative it wants to hold the viewer in suspense. The rules engine that drives this particular universe is meant to be discovered, and that is the joy of debugging Westworld – finding the rules.

Over the course of ten episodes, all the theories generated by the fans are an attempt to define the rule set of Westworld. What can the Hosts do? How much do they know? How far can they go to protect themselves? If Hosts look and act like the Guests, how do we know who is a Host or not? With each episode, new information presents itself, and theories are iterated and debugged.

At the end of the first season, it was reported that the Internet “outsmarted” the Westworld writers. The fact that many of the evolving theories about what was occurring in the Westworld universe were proven to be true was described as a sign that the show failed to live up to expectations.

This… is bullshit.

The fact that many of the popular theories were proven true indicates that Westworld is well designed. The narrative, the code, is proven to be structurally sound by the fact that viewers were able to infer the rules. A great majority of the viewers of Westworld were not obsessing over the apparently changing typeface on Dolores’s milk can. The majority of the viewers were casually consuming the show, but even by themselves they were building and debugging their rule set for the Westworld universe. They were perhaps more shocked by the twists at the end, but they were equally satisfied that twists made sense given their rule set.

A narrative whether it’s built with words or code must tell a complete story. The constitute parts must clearly contribute to a coherent and pleasant whole. Eli was a poor story teller, but Westworld’s story has just begun to be understood.

Leave a Reply

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

10 Responses

  1. I think this piece does have spoilers, the mention of the surprise twist at the end is a spoiler. You may want to update your disclaimer. However, this was a very enjoyable article. And I love the show.

    • rands 7 years ago

      I disagree that a series ending with a surprise twist is a spoiler. Thanks for the feedback!

  2. Chris Koerner 7 years ago

    I enjoyed this analogy as both someone who works with developers, and a Westworld fan. A little friendly criticism.

    “From the minds of Jonathan Nolan (Memento, The Dark Knight series, and Interstellar) and Lisa Joy”

    Lisa Joy was a writer on two successful and award-winning television shows (Burn Notice and Pushing Daisies) and a producer on the former. Surely not intentional, but listing the works her husband is known for, but not extolling the virtue of her own work, seems a little lopsided.

  3. anonnymoose 7 years ago

    “It is a software engineering right of passage…”

    This should read: “…rite of passage…”

  4. CdrJamesonCdrJameson 7 years ago

    The problem I have with these shows is they don’t have the equivalent guarantee of the code – they might not even compile, ie. make coherent sense – in which case I’m really wasting my time (cf. Lost, Heroes, the last series of Battlestar Galactica, The Killing)

    This means I wait for other people to validate TV series before I spend my time on them. Luckily, they don’t seem to mind being the TV equivalent of Lint.

  5. The show is poorly written, period. It has no consistent logic, no real motivation for its characters and utterly no emotional core. It is pompous clichés masquerading as wisdom, cleverness masquerading as intelligence, and glossy surface masquerading as beauty. No accident that everyone I know who likes it is a heavy pot smoker. The show is just plain dumb.

  6. Njlopp 7 years ago

    Fascinating. Time to watch Westworld

  7. Jen Bunk 7 years ago

    Yes! This article is a nice antidote for my Westworld withdrawal. 🙂

    Having “complex depth” is the perfect descriptor. I love the show and plan on watching it at least once more before Season 2 comes out.

    It’s like a fine wine. You appreciate it more with every taste.

    And like reading someone else’s code, to really appreciate it from multiple perspectives, you have to swoosh it around a little – read, debug, repeat.

    Cheers! 🙂

  8. Mike Lewis 7 years ago

    The problem with stories and software starts when the developer/writer is asked to go beyond the original story arc or design specs. When you have to add unanticipated characters, functions, sub-plots, features, etc. even the best code or story can suddenly turn to spaghetti. Westworld’s success may mean that it will live for years beyond the plans of it’s original writers. Will they be able to keep the same “rules” in place, or will they break them to keep suspense alive?

  9. In defense of Eli:

    Code, like the show West World can be exploratory, especially if you are learning or even just applying a new (to the developer) technology, or known technology to a new problem. Also like West World there is a point where the mistakes in code design begin to appear and minor adjustments to the code begin to cross back on itself giving that spaghetti appearance and unexpected consequences. Given time, noodles are stretched into neat rows and it looks like a well-researched and designed application (kinda like making sausage).

    Unfortunately when you take over someone else’s work, the first place you visit are the problem areas where the WTF’s are concentrated. This could be due to changes in requirements, changes in design or simply hacking out something so that you can work on another section of the code. Eli may have had a plan, but he may not have been able to realize it.

    Today’s technology allows developers to code first (some vendors even encourage it), which is OK since refactoring tools make de-spaghetti-fying it very easy, but at some point a design decision needs to be made and documented, if only to define the point of completion. Also, code without comments is play code, there is no such thing as self-commenting code. Code should be reviewed and comments make that process much easier. Any good code will be updated and comments make that easier as well. Un-commented code is throw-away code.

    West World started and ended like the original movie (a favorite of mine) but everything in between seem like a random walk trying to fill in stories that did not exist in movie. Lots of new technologies thrown in for no known purpose.