I Made a Star Wars Programming Language Called "The Force"

C-3PO with a missing leg

I’m standing here in pieces and you’re having delusions of grandeur - C-3PO

Background

Over the last month-ish I’ve been working on a programming language entirely made up of Star Wars quotes called The Force. Though folks who know me might be surprised, it wasn’t even my idea! A friend suggested it and we worked on the basic design together (which means I have excellent friends). And this is the result!

Do it!
    The Sacred Jedi Texts! "Hello there\n"
May The Force be with you.

For Computer Science nerds: The Force is a stack based, interpreted language, with dynamic and strong typing. It’s primary design goal was to optimize for number of quotes. And it’s built with Rust!

It has most the standard things you’d expect: variables, while/for loops, if/else, strings, booleans, floats, math, logic, and equality operations, functions, and of course, a Noop.

Example

Here is a classic Fizz buzz example.

Do it!
    <(-.-)> Declare variables, you must.
    Size matters not. limit
    Who, mesa? 100

    Size matters not. currentVal
    Who, mesa? 0

    I am the Senate! loop
    Who, mesa? From a certain point of view.

    I am the Senate! dividesThree
    Who, mesa? That's impossible!

    I am the Senate! dividesFive
    Who, mesa? That's impossible!

    I am the Senate! otherwise
    Who, mesa? That's impossible!

    Here we go again. loop

        <(-.-)> Judge me by my divisibility, do you?
        What a piece of junk! dividesThree
            I am your father. currentVal
            Never tell me the odds! 3
            I am a Jedi, like my father before me. 0
        The garbage will do.

        What a piece of junk! dividesFive
            I am your father. currentVal
            Never tell me the odds! 5
            I am a Jedi, like my father before me. 0
        The garbage will do.

        What a piece of junk! otherwise
            I am your father. dividesThree
            There is another. dividesFive
            Always with you it cannot be done.
        The garbage will do.

        <(-.-)> Fizz. Buzz. An interviewer craves these things.
        Do, or do not. There is no try. dividesThree
            The Sacred Jedi Texts! "Fizz"
        You have failed me for the last time.

        Do, or do not. There is no try. dividesFive
            The Sacred Jedi Texts! "Buzz"
        You have failed me for the last time.

        Do, or do not. There is no try. otherwise
            The Sacred Jedi Texts! currentVal
        You have failed me for the last time.

        The Sacred Jedi Texts! "\n"

        What a piece of junk! loop
            I am your father. limit
            Impressive. Most impressive. currentVal
        The garbage will do.

        What a piece of junk! currentVal
            I am your father. currentVal
            Your lightsabers will make a fine addition to my collection. 1
        The garbage will do.
    Let the past die.
May The Force be with you.

I can’t say it’s fun to write, but it’s certainly fun to read.

Instructions on how to install and use it are here and you can find more information about the language itself here.

Learnings

Through the process, I’ve learned quite a few things, both about Star Wars, Rust, and projects in general. Here are some of the highlights

Star Wars

Apparently a lot of the Star Wars quotes I knew, were actually wrong. Now, I knew that the famous Darth Vader quote was not “Luke, I am your father”, which is a common misconception (it’s “No, I am your father” by the way). For instance, I did not know that Yoda’s “Always with you what cannot be done.” and General Grievous’s “This will make a fine addition to my collection.” are actually “Always with you it cannot be done.” and “Your lightsabers will make a fine addition to my collection.” respectively. Neither are huge changes, but I felt like my world had been fundamentally altered.

Also, it’s surprisingly difficult to search most of the less iconic Star Wars quotes online to verify the grammar. A combinations of people misquoting them, sites with small quotes lists and great SEO, and drafts of the scripts that don’t reflect the movies, meant I spent a while checking everything (and I probably still messed up something).

Finally, for “research”, we watched all the Skywalker Saga movies (in release order for those wondering). I truly did not appreciate how rough Attack of the Clones was to watch. But I now truly appreciate how much fun it is to roast Attack of the Clones haha. Shameless plug: You can find out how much (or little) I appreciate about The Last Jedi and The Rise of Skywalker.

Rust

This is not the first Rust project I’ve worked on, but it’s certainly the biggest. I won’t say I fully understand the borrow checker, but I certainly feel more comfortable with it now. Which has certainly increased my confidence and productivity with the language.

Two things I really liked were how:

  1. Once even non-trivial changes compiled, it almost always worked as intended
  2. Rust fights moves towards making things overly complicated. Which is a good sign of when I should “go home an rethink my life” (or just try another approach)

Though I love Rust dearly, I still find it’s module and import system unintuitive. It’s something I have to look up each time I start a project. I’m sure if I used them more, I’d be more comfortable, but I can’t help the think something could be tweaked to make a better experience.

But, cargo and the other tooling make it so easy to run, test, re-test, re-test some more, and publish! It makes up for those negative experiences.

Projects

This is the first substantial project in a while that I stared, consistently worked on, and then got to a “finished” state (not that anything is ever done). It’s not super polished or anything, but it’s has something around 50 hours of work and learning put into it. It’s not terribly useful, but it’s the right kind of stupid that is fun.

I have lots of projects I want to do, but never commit to or take little stabs at over a long period of time. I think for a lot of things, that’s fine. If I can’t commit the energy to work on something, it’s probably not important enough to me or I’m just not in a state to be working on projects anyway. And with those projects I work on every once in a while. They act like a nice breather to do something low stakes and different in-between bigger things.

But man, it feels really good to get something out the door. It feels like energy well spent. Plus, my mind can now stop micro-obsessing on this project. That frees up some brain waves to start thinking about the next one, without feeling like I’ve just abandoned a baby somewhere.

I’m going to try working on more side projects like this. Especially if I can bring in other folk, which is motivation for me to keep going and just more fun.

Conclusion

I apologize for the ramble, I’ve had a lot of thoughts bouncing around for a bit now. If the project at all sounds interesting to you, please head over to the GitHub page where you can find links on downloading and using The Force! Feel free to file bugs, submit example code, add features, etc. I’ll help out where I can.

Oh, in case you’re wondering, yes, I have added that I can use The Force to my Linkedin (which totally wasn’t the true reason behind this or anything…). May The Force be with you.

Till next time,
- Matthew Booe

Related Posts