Maker vs.The Matrix: Agent JavaSmith, pt.1

Alex Jukes
5 min readMay 21, 2017

For the first five weeks of my time at Makers Academy, we had been writing code in Ruby. Then, just as I began to feel like I actually understood some stuff, along came a project where we had to use JavaScript and that silly idea got blown out of my head.

So… many… semicolons!!! ;;;;;;;

Unlike Ruby, which is a class based computer programming language, JavaScript is a prototype based language. Not sure what that means? Welcome to my world in week 5.

“Wait, you actually thought you knew stuff about coding? AHAHAHAHAHAH”

As the sharp eyed among you may have noticed, there’s already a bit of a theme to this blog. And no, it’s not just the Matrix — if you weren’t ready for a whole heap of coding and gifs from a late 90s cyberpunk classic, I would recommend checking out my first post before diving any deeper into the rabbit hole.

No, this time I’m going to talking a little bit about the core antagonist of the trilogy: Agent Smith. Why? Because I believe that Smith, and in particular the difference in his character between the first and second Matrix films, is actually a pretty good way of understanding the difference between a class and prototype based computer language too.

Don’t believe me? Very sensible. But let’s see how we go.

A Slave to the System

In the first film, Agent Smith is part of the Matrix. As Morpheus explains to Neo, in a particularly dope example of sci-fi exposition, Agents are sentient programs that can take control of anyone that is still connected to the system.

What would that look like if it were actually written as a program? Well, I’m not at the level of being able to code virtual reality simulations to enslave humanity quite yet, but let’s imagine the Matrix was written in Ruby. It might look a little like this:

class Agent
def initialize(name, appearance)
@clothes = "Grey suit"
@weapon = "Desert Eagle"
@sunglasses = true
@name = name
@appearance = "White dude who looks like " + appearance
end
end

This is an Agent class. Since all Agents share lots of common attributes, in Ruby it makes sense to create a dedicated class for them. This class acts like a template. When the Matrix makes a new Agent, we say it’s created a new instance of an Agent, to which we then can add individual details. Let’s create some Agents:

Smith = Agent.new("Smith", "Business Elrond")=> #<Agent:0x007f91dba3e368
@clothes = "Grey suit",
@weapon = "Desert Eagle"
@sunglasses = true,
@name = "Smith",
@appearance = "White dude who looks like Business Elrond"
@exploded = false >
Jones = Agent.new("Jones", "Clark Kent if he didn't have Superman as an alter-ego and just worked a boring desk job")=> #<Agent:0x007f802d96f1e0
@clothes = "Grey suit",
@weapon = "Desert Eagle"
@sunglasses = true,
@name = "Jones",
@appearance = "White dude who looks like Clark Kent if he didn't have Superman as an alter-ego and just worked a boring desk job"
@exploded = false >

Boom! We have some Agents!

And you thought your morning commute to work was painful.

Both Agent Jones and Agent Smith are individuals. They have a unique ID number, which Ruby automatically generates, as well as certain attributes like their name and appearance which are specific to them and are supplied by the Matrix upon initialisation.

The important point here is that while they are unique instances of Agents, both Smith and Jones are part of a hierarchy of classes. They, like the denizens of the Matrix, are just part of a wider system — a system in which they are instances of an Agent Class, which itself is just an instance of a Class object. Ruby is a hierarchy of different objects, each inheriting properties from the object above it. If you follow the chain far enough, you reach the fundamental root, which is the Object object.

This is why Ruby is an Object Oriented Programming Language, and why it is often said that everything is Ruby is an object: because if you follow the chain far enough, that’s what everything really is.

My brain when I think about this stuff.

So Agent Smith is part of of our Ruby Matrix hierarchy. That means he can be given a whole host of advantages over regular humans inside the virtual simulation, such as super strength and speed, but those are derived precisely from his privileged place within the system.

When Neo realises he is The One, he truly understands what Morpheus had tried to explained to him earlier in the film: that while Agents are given power by the Matrix, they are also shackled by it. Freed from having to obey the same rules of reality that Agent Smith has to, Keanu Reeves can now lay some serious smack down on our Ruby generated baddie.

When someone puts their leg down like that, you know you’ve been schooled.

Neo, like us, can now see the code that Agent Smith is based on. He can also re-open the Agent class and define a new method that does this:

Class Agent   def explode
@exploded = true
puts "Agent #{@name} exploded. Ouch"
end
endSmith.explode
=> “Agent Smith exploded. Ouch”

Not bad for a few lines of code, eh?

So by the end of the first film, Neo has learned some Ruby. Awesome. But things are about to get a whole lot more complicated. Here comes JavaScript.

‘Wait, there are 20 brackets in this one function? I’m out.’

Part 2 coming soon!

(hit the follow button below if you want to find out what happens next!)

--

--