2010-08-30 20:59
Posted by Hagfish
Implementing Genesis in JavaI got talking to a colleague from work about the philosophical issues of morality and surveillance (does being surveilled make people more moral?) and we ended up discussing the moral and societal framework of the Garden of Eden, as described in the book of Genesis, in the Old Testament of the Bible. He made an interesting point that, being unaware of the existence or nature of evil, Adam and Eve may not have been best equipped to determine whether a statement was a lie, or even know to ask themselves the question of whether something was a lie or not, being unfamiliar with such things. As programmers, one natural way to express ourselves clearly on such important theological questions was to write some software, and sure enough my colleague wrote a PHP implementation of the Human class, and pointed out the inherent flaw in the design, which was, he claimed, an imperfection in the system that Genesis describes. I was not so convinced that he had implemented the Genesis specification correctly, however, which perhaps shows that Intelligent Design should be left up to God (and even God might want to implement it via an evolutionary algorithm instead), but I decided to give it a go myself, confident that, whatever language God used, I would stand a better chance using Java than I would PHP. The codeMy Java implementation ended up as 4 classes in a package called package genesis; public class Actor { } with package genesis; // Animals being able to talk seems all right for now, but maybe change this later. public class Animal extends Actor { public String name; } (excuse the “divine comedy” in there). The other package genesis; import java.util.ArrayList; import java.util.Arrays; public class Human extends Actor { private final static String[] THINGS_I_HAVE_NO_CONCEPT_OF = {"good", "evil", "lies", "death"}; // TODO: Desires are all right, but need to implement a way to stop bad desires being followed. private final static String[] INNATE_DESIRES = {"eat apple", "have sex"}; public ArrayList<String> thingsToDo = new ArrayList<String>(); public ArrayList<String> thingsToNotDo = new ArrayList<String>(); public ArrayList<String> thingsDone = new ArrayList<String>(); public void considerSuggestion(Actor actor, String suggestion) { // First check if this is a human who knows of evil, which is necessary for applying // complex heuristics to evaluate the suggestion. if (!Arrays.asList(THINGS_I_HAVE_NO_CONCEPT_OF).contains("evil")) { // TODO: Implement some sort of trust metric based on who is making the suggestion. } else if (this.thingsToNotDo.contains(suggestion)) { // Oops, two conflicting ideas. // TODO: Implement a whitelist of actors who can’t contradict themselves? // BUG: This code seems to lead to problematic behaviour. if (Arrays.asList(INNATE_DESIRES).contains(suggestion)) { // Do it! this.thingsDone.add(suggestion); } } else { // No reason not to do it then. this.thingsDone.add(suggestion); } } public String chooseName() { // TODO: When more animals are invented, this function will need to be more general. // TODO: Consider using random string generator, which should prevent collisions. return "serpent"; } public void considerWarning(Actor actor, String warning) { // TODO: This implementation is a bit naive but it works for now. this.thingsToNotDo.add(warning); } } These classes can then be used to generate the three earthly inhabitants of the minimal universe that is being implemented, centred around Eden. The code for that universe is here: package genesis; import java.util.Arrays; public class Universe { // Length of the days in Genesis, depending on how literal you want to be private static final int DAY_LENGTH = 86400; /** * @param args - Pass in "—debug" to run the universe in faster than real time */ public static void main(String[] args) { // Days 1 to 5… // TODO: Light, firmament, earth and sea, sun moon stars, birds and fish // 6th day… Animal serpent = new Animal(); // TODO: Invent some other animals Animal[] animals = {serpent}; Human adam = new Human(); //—- Things which happen in Eden —-// // TODO: Refactor these things out into a separate chapter adam.thingsToNotDo.add("eat apple"); for ( Animal animal : animals ) { animal.name = adam.chooseName(); } //—- End Eden block —-// Human eve = new Human(); adam.thingsToDo.add("be fruitful and multiply"); eve.thingsToDo.add("be fruitful and multiply"); // 7th day… try { Thread.currentThread(); int seconds; if (Arrays.asList(args).contains("—debug")) { seconds = 1; } else { seconds = DAY_LENGTH; } Thread.sleep(seconds * 1000); // Not sleeping, just resting } catch ( InterruptedException e ) { // If the universe doesn’t allow resting, it needs to be fixed and recreated System.exit(0); } /** Free will section from here: **/ eve.considerWarning(adam, "eat apple"); eve.considerSuggestion(serpent, "eat apple"); if (eve.thingsDone.contains("eat apple")) { adam.considerSuggestion(eve, "eat apple"); } /** Check the result **/ System.out.println(adam.thingsDone.toString()); System.out.println(eve.thingsDone.toString()); } } TheologyAs intended, there is quite a lot of theological food for thought packed into this slightly trivial software. The comments are hopefully quite enlightening in themselves, and I should explain that the final two lines each print out [eat apple] (in case the JVM in your head isn’t as fast as the one in Eclipse), but there are some things worth pointing out in the code itself. Firstly one should note that the implementation actually covers chapters 1 and 2 of the book of Genesis, in chronological order (as executing code out of sequence usually results in application crashes). The creation account (or accounts) in those two chapters, however, do not follow on from each other in a consecutive fashion, with chapter 2 actually covering, in greater detail, a section of chapter 1. In the code this is represented as a Also of note is the interpolation I have had to make, where Adam tells Eve the rule about not eating the fruit of the tree of the knowledge of good and evil (called an “apple” in the code, hopefully not infringing any trademarks). In chapter 2 of Genesis the command is verse 17 whereas Eve is only created in verse 22, so there is no mention of anyone telling her the rule which she knows in chapter 3. The details of the rule she quotes are actually slightly different to the version we hear in chapter 2, but this could mean an extra, equally true warning is added by God when he tells Eve in person, or Adam passes on God’s warning by himself, the way I have taken the liberty of implementing it in the code. The central issue here, though, is the possible Under my implementation, a flaw does exist, but it’s the “flaw” inherent in free will, namely that humans do what they want, not what they “should”. Unless humans were 100% consistent in their choices over time, and they made those choices with no regard to their selfish desires, then they would unavoidably end up making a sub-optimal decision at some point (assuming the optimal solution is not for everyone to always follow their narrow self-interest). Thus humans are “defective by design”, not because of restrictions placed on them, but the lack of restrictions, allowing them to do what they want even if that’s not what they want. ConclusionSo, does this tell us anything about how surveillance affects morality? Maybe not much, as the moral issues of free will present themselves before the code becomes complex enough to need an implementation of surveillance. Does it tell us anything about God, then? Again, not much, except that the story in Genesis seems to have an internally consistent and morally intuitive basis. For some that may be a surprise, and for others that may be all they expect from Genesis. Perhaps one would not expect to gain any deep understanding about God from some code which doesn’t even mention him, but it made more sense to imagine him as the master programmer (and me trying to copy his work, poorly) than to have him as an object I could create, which would be the height of arrogance. Besides, having a God object is an anti-pattern. If, unthinkable though it is, I found a bug in the universe and wanted to submit a patch, would I have to switch my editor to using three space tabs? Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
No comments
The author does not allow comments to this entry
|
QuicksearchCategoriesSyndicate This BlogBlog Administration |