Monthly Archives: March 2006

Musings on the nature of religion

Following the recent discussion of anthropology and religion, I dug out one of my old anthropology essays which I did at the end of my first year at university – now almost 5 years ago.

It was called “The Meaning of Life – A critical essay” and as I reread it, with some vague memory of it containing some interesting analysis, I found that it really was quite bad: Besides being just as pretentious as the title suggests, it was poorly structured, with bad argumentation and use of empirical data, and a very sloppy and uncritical approach to the theoretical sources used.

Basically, it sucked. But it was quite a worthwhile read, because it gave me a chance to compare how I’ve developed these basic skills of academia over the past 5 years. I mean, it would truly be awful to find out that I wrote better stuff back then, than I do now. But on the other hand, the essay did contain a uncompromising wonder and naïve interest that you simply don’t see often enough in academia.

So I took that old essay (written in Danish) and pulled it apart, and translated the bits into a sort of dialogue touching upon the same topics, but without trying to be more than superficially academic. It gives a sense of connection through time – to a younger self. To argue with yourself and compare notes. To revisit that old argument and use the dialogue form to ask all the questions that you still wonder about, but more or less have pushed aside. I can only recommend visiting your earlier academic self and negotiate your experience with your arguments of earlier times. It gives a sense of perspective, and probably brings you closer to what brought you to academia in the first place.

Don’t know about the answers, though.

Programming 103

In all computer programs, all decision making can eventually be reduced to a question of true or false. And because of this, Boolean expressions – truth values – play a central role in programming.

Boolean expressions use relational operators and take primitive types (integers, decimal numbers and single characters) as arguments. The result of boolean expressions are always a boolean value – true or false.

There are the following relational operators:
– greater than
== – equal to (remember that a single “equals sign” means assignment of a value to a variable)
= – greater than or equal to
!= – not equal to

When you compare primitive types in a Boolean expression, simple numbers like integers are easily compared. Decimal numbers on the other hand require some approximation and you can set a constant – usually called TOLERANCE – to determine how much decimal numbers are allowed to diverge before they no longer are to be considered “equal to” or “greater than”.
Single characters are compared by their unicode numbers, that means that A is actually compared through its numerical representation 65.

Reference types such as Strings can’t be compared directly, but should be compared through specialized methods under the String class called “.compare.To” and “.equals” which can be used to compare two strings as two rows of char types.

Boolean expressions can also use logical operators which take boolean arguments and offer resultant types that are boolean.
There are the following logical operators:
! – not
&& – and
|| – or

The way these expressions work in a computer program is whenever a decision is being made. Since the computer only can react upon what it has been programmed to react upon, you have to foresee and program every reaction the program needs to make. The basic way to do this is to set certain conditions that needs to be fulfilled in order for the program to progress. There are several different ways to do this. The simplest is the IF statement:

if (boolean expression)
(then) statement

Some other programming languages need the syntax to be if (this condition is met) then do (this statement). Java doesn’t use that, but I included it here, to make it more obvious how it works.

In a real program, an IF statement might look like this:

if (X>0)
System.out.println(“Have a nice day!”)

Thus, if variable X is greater than 0, the program will print out “Have a nice day!” if the condition isn’t fulfilled, it’ll just skip that part of the program and continue onto the next bit.

This is very basic decision making, and it can be expanded in various ways. There’s the IF-ELSE statement, that allows for two different courses of action, depending on whether the set condition is fulfilled or not:

if (X != 2)
System.out.println(“Have a nice day!”);
System.out.println(“Thank you!”);

Here, if X is not equal to 2, the program will print out “Have a nice day!”, otherwise it will print out “Thank you!” before continuing with the rest of the program.

Then there is the WHILE statement:

WHILE (boolean expression)

this kind of decision continues to run, until the boolean expression turns false. This creates the possibility of making an Infinite Loop – eg. if the loop condition is always true.

A WHILE statement might look like this:

while (X>0)
System.out.println(“Have a nice day!”);}

Usually, the WHILE statement only uses the next one statement if the condition is met (that variable X is greater than 0), but by putting several statements in {curly braces}, all of those statements in that Code Block are considered as one statement by the initial If. This bit of code will first decrement X by one and then print the words “Have a nice day!” on the screen. Then it will then return to the initial WHILE, and if X is still greater than 0, it will do the same statement again. Thus, if X was set to 5, the WHILE statement would loop 5 times, decrementing X and printing the words 5 times, until X no longer was greater than 0. If there was no decrementation of X, the loop would be an infinite one.

Then there are DO loops, which are very similar to WHILE loops, except for the fact that the condition isn’t evaluated until after the loop which means that the DO loop always runs at least once:

while (boolean expression)

or as a proper example:


which will print out the word “what?” at least once, before examining whether the condition is actually met. If the condition is met (X is equal to 5), then it becomes an infinite loop, as there is no incrementation in the DO statement.

And then there are FOR loops which work best when we already know how many times we want the loop to run:

for (initialisation; condition; increment)

This loop first initializes a variable, sets a condition through a boolean expression, and increments a value. Then performs a statement. It could look like this:

for (int X = 1; X

So, we initialize X with an integer value of 1, then we say, as long as X is smaller than or equal to 4, increment X by one and print the message “X is still smaller than 4”.

Now, with these different forms of loops, it is possible to make much more interesting programs. A really simple one is this MinMax program that I wrote. It allows for the input of two numbers, and outputs the greater of the two.

Or the slightly more advanced Penge program which, based on the user’s input, is capable of adding up your various coinage to tell you how much your loose change is worth.

Yet, these programs are also very simple. As I mentioned earlier, Object Oriented Programming (OOP) such as Java is focused on the idea the program code should be divided and encapsulated as much as possible so that the individual elements – or objects – can be instantiated and modified easily without having to rewrite the entire code.

Java in particular, being a relatively young language with a set design in mind, takes this instantiation to new levels. For instance, Java doesn’t contain a GOTO statement. The GOTO statement is the most primitive form for programming loop you can make. When the program reaches the GOTO statement, it then jumps to the line specified by the statement, thus jumping to another point in the program, possibly to a point earlier in the program, thus looping a section of the code until a set condition is met (if no condition is set, it would be an infinite loop that would continue until you manually stopped the program or the computer couldn’t handle it anymore).

Here’s a simple example of a GOTO program – written in the BASIC programming language:

20 GOTO 10

which basically will print the line “BOB IS AWESOME!” again and again and again until you stop it.

Though most older programming languages have the GOTO statement, many computer scientists consider it to be a sign of poor programming practice as it would often lead to “spaghetti code” – code full of internal references making it difficult to read and understand – even for the programmer who wrote it.

Java avoids this by design and forces the programmer to divide his program up into several class objects with small but clear functions. All of these objects are then called by the Driver class which contains the main method – where the execution of programs usually start.

The execution of a program is decided by the “Flow of Control”. At first, flow of control recides with the main method, but the main method can in turn call other methods in other objects to perform a function contained within them. By calling another method, the main method transfers flow of control to that method, and they retain control until they in turn call another method or finish their function and returns flow of control to the main method.

This means that Java programs often consist of small sections of code, of methods and classes that are called when needed. Critics of OOP argue that this practice easily results in “Ravioli code” which is the opposite of spaghetti code: A lot of small, encapsulated bits of code that nobody really can tell apart and work out.

In both cases it is a question of being able to read and understand the code in order to be able to modify it, rather than a question of being able to run it. To have maintainable code.

At first, I found that I really just wanted to put in a GOTO statement into my program, to say “just do that bit again”, but since Java doesn’t allow me to do that, I had to change my approach. Instead, I made two separate classes of code: First, a driver class, which really doesn’t contain any more than the beginning of the program, and which then calls one of the three methods in the GameLoop class. By having the code separated like this, you call the bits of code by writing the method name – eg.


which transfers flow of control to the intro method in the GuessingGameLoop class. The program works okay, and it is basically a guessing game where the computer “thinks” of a number between one and ten, and then offers you a chance to guess it. Using the loops explained above, I managed to make in such a way that you can play as many times as you like, without having to begin the program again.

If you want to try these little programs out, make sure you have Java 1.5 installed on your computer, then download the compiled .class files:


and run them from a command line interface using the command

java nameofprogram.class

– just make sure that all of the files are in the folder that you’re trying to run them from. Note that you can’t run GuessingGameLoop on its own, only through its driver class.

Naming the Internet of Things

Apparently, what used to be known as Ubiquitous Computing, as defined by the late Mark Weiser, has hit a major semantic blizzard.

The technology to make Ubiquitous Computing happen is finally getting somewhere, with RFID (Radio Frequency IDentification) chips that look set to replace barcodes, and generally make objects carry information in a completely new way. There’s even talk of putting these tiny chips in the new Euro notes to make them traceable.

And as the technology is gaining momentum in technologist hype machines in blogs and keynotes around the world, design and computer trend researchers are all up in arms trying to find new ways to talk about it. See, UbiComp is just all kinds of unsexy, and new words are needed, stat.

And science fiction writer Bruce Sterling argues, the way that these neologisms are coined and used is central to our understanding of the potential of this technology. In a recent keynote, he lists just some of all the new terms that are currently flourishing.

Techno-anthropologist of sorts and expert in these ways, Anne Galloway, have begun compiling a bibliography of The Internet of Things which is well worth checking out.

As far as I can see, these theoretical discussions usually have little influence on the name under which new technology is eventually known. It seems that it is the hackers who develop these things, that usually get to pick the names – such as Google, Flickr, Wiki or Blog – words that really don’t seem to signify anything else. Maybe that’s the reason Sterling’s own Spime might succeed in the end.

Programming 102b

There are a lot of specialized operators in a programming language. A lot more than I’m familiar with. Some of these are called ??Syntactical Sugar? as they combine two or more the functions of two or more operators in a single statement.

For instance, instead of writing

a = a * (b / PI);

you can write

a *= a / PI;

thus condensing the expression a bit (though not necessarily making it any clearer).

There are also increment and decrement operators that adds one or subtracts one from a variable, like these expressions:

a++ = a +1;
–a = a ?? 1;

The difference in whether the increment operator is put before or after the variable is that the incrementation takes place before (prefixed) or after (postfixed) assignment of a new value to that variable. Thus

b = a++;

is broken into two statements:

b = a;
a = a +1;

and the same with

b = ++a;

which is the same as writing

a = a + 1;
b = a;

Our lecturer noted that all of this is, indeed, just sugar coating, and we shouldn’t use it if it confused us. But of course, it does exude a certain level of intellectual coolness to be able to use them successfully.

This sort of incrementation is the basis for the name of the Object Oriented Programming language called C++. Basically, it’s the programming language C + 1. I understand that hackers enjoy this sort of wit.

When the computer determines the order in which to calculate an expression, it usually takes each operator from left to right. But it runs from left to right on several levels of precedence, depending on their operators.

These levels of precedence are (simplified):

1st level: expressions in ( ), ++ and ?? (postfix) (evaluated from left to right)
2nd level: unaries (eg. +2 or -3), ++ and — (prefix) (evaluated from right to left)
3rd level: * / % (evaluated from left to right)
4th level: + – (evaluated from left to right)
5th level: = += -= *= /= (evaluated from left to right)

This means that when the computer resolves an expression like this:

weight / (height*height) = bodyMassIndex;

it first calculates the expression in the parenthesis, then divides that expression before assigning the result to the variable bodyMassIndex.


Right, then. Enough theory. Here’s the source code for my first program. It is an applet – which means it is meant to run through a web page. Like this.

Basically all Java programs borrow bits of code from pre-defined libraries or packages, making the “standing on the shoulders of giants” line even more concrete as you use other people’s code as the basis for your own in order to avoid reinventing the wheel.

For applets, some of the most relevant packages are the “swing” and “awt” packages which contain code that allows you to draw geometric shapes in webpage.

Now, as I mentioned earlier, there are three kinds of Java programs – regular command line programs, GUI programs and applets. Each use different commands to achieve their effects. Applets and GUI programs are much better at handling graphics while command line programs are much better at handling text.

We started out with a simple applet to generate coloured circles in order to give us a clear feeling of making the computer do something with programmed commands. As the Assignment Sheet shows, we started out with a working program that drew a yellow circle. We should then modify the program to draw another, smaller circle on top of the yellow one, and calculate the area of both.

By simply reusing the commands already in the program and changing the parameters (sizes and colours), this proved fairly easy.

Following that, we were given a wide range of various small assignments to do. Such as this program which prints out


in just one statement by using the “\n” command to force a new line in the middle of a string.

But all of these programs were limited in that they couldn’t be altered when run, and that they couldn’t respond to changes or unforeseen circumstances. Which is where boolean values, loops and user input become central. More on this soon.