God is a software engineer. Change my mind.

Time to literally play God

Have you ever wondered how eating works?

Next, let’s do a bit of design. What would God do to engineer the process of eating something? Eating is the first step of that whole digestion process. Yet both are separate. Since I assume that the All Mighty is a Clean Coder, we will split that into two actions Eat() and Digest(). These will be the first methods of our Digester interface. Why Digester and not Human? Well, as far as I know, we are not alone able to eat and digest stuff. Animals and some plants can eat and therefore digest. Let’s have a first look at our Digester.

public interface Digester
{
void Eat();
void Digest();
}
public interface Item
{
}
public interface Digestible : Item
{
}
public interface Digester
{
void Eat(Item item);
void Digest();
}

Exceptions a.k.a things you may not put in your mouth but God lets you do it anyway

Let me introduce you to a guy you may not know, 2008 JD (pronounced noob). As one does, 2008 JD would suggest throwing an exception if someone tries to eat something they can’t digest like a big rock. No, 2008 JD is not stupid but has a lot of learning to do. Indeed, 2008 JD did not know what a variable nor a compiler was so do not take advice from him.

Things that you literally cannot digest because people tried and had troubles

Back to the rock thing, we would count it as an item that you can technically eat but not digest. so let’s make our Digester a little less abstract. To do that we will make it an abstract class that can choose not to digest everything that gets eaten. Actually, it would make more sense now to break the Digester into a Eater and keep the Digester defined by its ability to digest. Now let’s see what our updated Digester would look like.

public interface Digester
{
void Digest();
}
public abstract class Eater : Digester
{
private Queue throat = new Queue();
public void Eat(Item item) {
if (item is Digestible food) {
throat.Enqueue(food);
}
else {
throw new LiterallyCannotEatThatException(item);
}
}
}

Things you can digest more or less safely

But how does the food impacts us? Well, when you eat something it has an impact on you, it interacts with you. When you eat something, you know based off past experiences or common knowledge how it should taste like and how it should make you feel. Note the use of “should” here.

public interface Item
{
void Interact(Item item);
}
public abstract class Eater : Digester, Item
{
private Queue throat = new Queue();
public void Eat(Item item) {
if (item is Digestible food) {
throat.Enqueue(food);
}
else {
throw new LiterallyCannotEatThatException(item);
}
}
public void Digest() {
while (throat.TryDequeue(out var digestible)) {
digestible.Interact(this);
}
}
public void Interact(Item item) {
// empty like most relationships…
}
}

Time to venture in a zone of danger

Now we have our simple strategy in place for an eater to consume items. What now? We need an interface to express that we are mortals and that food does things to us. That sounds a little too specific so I will just add one method to Item because it’s getting late and I need to go and work in the morning. (Yes these things take time to write…).

public interface Item
{
void Interact(Item item);
void Die();
}
public abstract class Eater : Digester, Item
{
private Queue throat = new Queue();
public void Eat(Item item) {
if (item is Digestible food) {
throat.Enqueue(food);
}
else {
throw new LiterallyCannotEatThatException(item);
}
}
public void Digest() {
while (throat.TryDequeue(out var digestible)) {
digestible.Interact(this);
}
}
public void Die() {
// Except for PewDiePie a.k.a. 0 deaths
}
public void Interact(Item item) {
// empty like most relationships…
}
}
public class ForbiddenFruit : Item
{
void Interact(Item item) {
item.Die();
}

void Die() {
}
}

Away from the original sin and back to the original point

I may have only put an afternoon of formulated thought into this but I don’t believe my mind will be changed on this. I already had a few sparks about this in the past but not the point of blogging. God is a software engineer, definitely the best there is the best there was and the best there will ever be. At least for now.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store