To Love Another Person

As I might have mentioned before, I don’t believe in the idea of a benign, benevolent God ruling over our lives. And it’s not because of a lack of evidence to support that view, but an excessive amount of evidence to disprove it.

However, as I have also mentioned before, I find the concept of Object Orientated Programming to be bordering on the divine. There is just something about the innate beauty and style of it that makes it brilliantly sublime,

And, since I have had a lot of free time on my hands this week (mostly while waiting around for shop owners to finish up with customers so they could help me with the field testing), I have been giving a bit of thought as to why I find OOP to be as amazing as it is.

Basically, it comes in two parts. But before I start, I will give a brief explanation of OOP for everyone who doesn’t know what it is (because if you aren’t a software engineer, it is somewhat improbable you will have seen it anywhere else).

An Object (in computer terms) is a group of fields and methods (also known as subroutines – a series of instructions the computer executes) that are joined together by a single container.

Imagine, for a moment, a safe with a set of photographs in it. The photographs are the fields (something that has a value), and opening the safe is a method – something that lets you access the photographs (the fields). 

Or if you imagine a human being. The various aspects of the body (eyes, nose, shape, hands, brain, heart and so forth) are the fields, and the ability to talk, to see, to hear, to walk and so on are the methods.

This is a somewhat overly simplified explanation, but it is the basic idea.

The other two things that objects have are "properties" and "events".

A property is a specific type of method  that controls how you access the fields. So if you want to access the photographs in the safe, the property would ensure you have to be wearing gloves so that you don’t get fingerprints on them. Or if you are getting the colour of someone’s eyes, you have to take their glasses off first. 

An event is something that happens when the object is used in a certain way. So when you open the safe to look inside, it triggers an event to log that you opened. Or if you ask someone to make you dinner, it triggers an event to make the person ask you want you want. (This part is known as a "parameter" – something that the event gives to you so that you can modify it and give it back). 

This is a basic description of "an object". But, as with most things in computers and computer programming, there is so much more to it. And this is where it becomes a work of wonder and beauty.

The first major benefit of objects is that they are defined as a type – a template. You define an object for a car, and then you can use it over and over again, without having to redefine it every time. So you can use the same template for a car to create a Ford, a VW and a Nissan. And they will all have the same fields, methods, properties and events. 

This is known as resuability (or – to put it a better context – recycling) and is of HUGE benefit for software developers. 

The second major benefit is that you can create modified objects based on the original by inheriting from them. This part is – oddly – a great deal easier to explain, because it is almost exactly like the way a child is a modified version of their parent. If the parent is the original object, then the child inherits all the characteristics of the parent, but also has modified versions of these (because of their other parent). 

Objects don’t work exactly like this, but for all intents and purposes, it is the best way to imagine it. 

This is know as (unsurprisingly) inheritance, and it means that – for the example above – you can create a Ford Object, a VW Object and a Nissan Object and give each of those slightly different versions of the methods. So you can force the Ford Car to require a password before you can use it, but the VW car doesn’t require a password. But – in both cases – the method for putting the key in to the ignition is the same, because that was defined in the "car" object and isn’t changed in either of the children (the Ford or VW objects)

This is also a massive benefit, because it means you can easily create multiple objects that share a lot of the same behaviour but can have different characteristics if they need to. 

The third major benefit is that because all the fields, methods, properties and events are lumped together in one container ("the object"), it is very easy to move them around in the code, to store them in lists and other containers. Which means, for example, if you want to create a list of cars, you can put all of the objects defined above (Ford, VW, Nissan) in to a list and that will store all of the fields, methods and so on, so that when you pull it out again, you don’t have to mess around trying to get all the fields/methods/etc associated with it. 

This (again) is a massive benefit because – for example – if you are writing a program to store a list of students in your class, you can create an object to model the characteristics of a student, and use it over and over again for each of the students in your class and put them all in a single list, rather than having to store them individually (much like having a register of names rather than thirty pieces of paper, each with one name on).

And – if that wasn’t enough – it is possible to compile the code that represents the Object in to a single file which you can then give out to other software engineers. So they can use the Object in their programs, while you retain the actual source code (which is the most important part). It allows developers to share their skills and their knowledge – which is always a good thing (I am nothing if not a sharer) while not having to give away their hard work for free so other people can steal it and claim it for their own (I may be a sharer, but I have to eat). 

If you are with me so far, well done. These are fairly abstract concepts that – as I said – are sometimes hard to grasp if you don’t use them every day of your life. (If you are curious, I have been writing in Object Orientated Programming since the mid 1990s, which is why it is now second nature to me). 

But now I am going to get to how I can link this to looking in to the face of god…..

The first reason it is so beautiful is that you can describe the entire universe using this model. 

If you think about it, everything – from the smallest atom to the largest black hole, from the inanimate like a block of wood to something that is complex and very animate like a human being – matches this model.

An atom has protons, electrons, neutrons and mass – these are the fields. If you split it, you release a certain amount of energy – that would be an event.

A black hole has mass, dimensions and an event horizon. When you get too close, you get caught in its gravitational field – which you can use a method to calculate the range of.

A block of wood has dimensions. If you cut it in two, it (from a certain poi

nt of view) halves the size of the original block and creates a whole new block that is also half the size of the original. This would be a method (split) and you would define where you split it (half, quarter, eighth etc).

A human being also has dimensions (although, as a rule, you should not cut those in two. At least not while they are alive – people tend to frown on that sort of thing) but they also have a lot more. Thoughts, emotions, interactions with other people, organs, "fluids" (for want of a better phrase) and so forth. However, all of these can be modelled, to one degree or another (although this would lead in to more discussions about how computers work, how they store things and so on, which I am pretty sure you can live without for the moment). 

But it also leads me in to the second part of why objects are so good at representing the universe.

I mentioned properties earlier – these are the ways that manage how you interact with the fields. 

The properties come in four types – private, protected, public and published. 

Private properties belong to the object, and solely to the object. They can’t be accessed directly and can’t be used by any other objects. (These are actually what I referred to as "fields" – a field is essentially a private property).  

Protected properties belong to the object, much like private properties. They can’t be accessed directly and can’t be used by any other objects. However they can be used by any new object that descends from the parent object – all child objects inherit the protected properties, and can use them directly. 

Public properties belong to the object, but can be accessed by any other object and can be accessed directly. Generally they are used to provide access to the private and protected properties. Any child object will inherit these properties as well, and use them directly. (It also means that they can change how you interact with the private properties in the child, compared to how you interact with them in the parent if you want to). 

Published properties are a modified type of public properties, and for now I will leave it at that, because – again – the ins and outs of why they are different is somewhat complex.

Now – imagine a person. In fact – imagine you. 

You have "public properties" – things that other people can see without you having to do anything. These include height, weight, hair colour, eye colour, how many arms and legs you have, whether you are male or female. 

You also have "private properties" – things that other people can not see directly. These include memories, thoughts, feelings and so forth. People can get at these, but you have to let them – you have to use a "method" to let them access it. You can tell them your thoughts, you can write down your memories. You can post down your feelings on a blog like this. People can access them, but not directly. 

And you also have "protected properties" – things that other people can not see directly, but that you pass on to your children. DNA is the most obvious example of this – the average person on the street does not know what your genetic code is, but it is passed on to your children and they use it directly. 

Consequently, you could create an Object that represents you, with its private, protected and public properties, and it would pretty much be a representation of you. 

It would take a lot of effort, but it is possible to create an entire model of the universe using Object Orientated Programming. 

To start with a small example, a house is made up of rooms. The rooms are made up of walls, floors, ceilings and contents. The contents are made up of various materials and have their own unique properties. The materials are made up of atoms. The walls, floors and ceilings…. – well, you get the idea. 

So the house would be an object that is made up of smaller objects (rooms), and the rooms would be made up of smaller objects (walls, floors etc) and so on and so on until you get down to the proton/neutron/electron level at which point I think you can stop (although you can model the subatomic particles if you want!)

And what is a street but a collection of houses? And what is a town but a collection of streets? 

I realise I have wandered off my original thread – I get like that when I am explaining stuff – but, to return to my basic premise, everything I have explained above goes towards explaining why I find Object Orientated Programming is so…… beautiful. So wonderful.. Why, to me, it is close to an expression of the divine, the building blocks of the universe.

And – to take it a step further – if we can create an accurate model of the universe using objects, then perhaps we can understand how the universe works. Because, as any good hacker will tell you, the key to getting past a security system is to understand how that system works. Because once you understand how it works – once you have the source code in your grasp – then you can change how it works to fit your needs.

There are already examples of this – doctors and researchers break down the genetic code of viruses and diseases so they can create a cure for them. People who write anti-virus software (Avast, Sophos etc) do more or less the same thing – they break down the behaviour and binary code of the virus to try to write a counter to it (so it can be detected and neutralised). 

But imagine – just imagine – if you could break down the source code of the universe. What couldn’t you achieve if you could actually rewrite how the universe works?

However, since that is a long way off (maybe an eternally long way off), I will simply finish by saying that the implementation of OOP that exists is just so….. perfect that – to me – it is the closest we will get to understanding the universe, and to stare into the face of the divine.

Log in to write a note
October 30, 2012

This is pretty damn awesome.