When you study computers-science at the University of Paderborn you get taught the Java programming language in your first two semesters (which you might already know by then). Afterwards you get a brief introduction on other programming paradigms and the corresponding languages: C, Pascal, Lisp, ML, SmallTalk, SQL, Prolog, …
Starting from your third semester you are expected to learn any arbitrary programming language by yourself. That’s it. I don’t know if this equations works out or not. But if you encounter someone who claims to be a “software-architect” and did study in Paderborn and considers programming to be beneath him,… well I think you catch my drift.
I can only pity all people who consider programming as beneath them, because they miss out on one of the important lessons of computer science. Language does define how we think. If we can express some topic in such a way, that someone other with a certain background on that topic can grasp and understand it, then we have truly conceived that topic ourselves. Here the computer is nothing more than an unforgiving and impolite listener. You need to be concise and exact or everything will blow.
If all programming languages were equivalent from the programmers point of view, everything would still be written in Assembler. This is where we Nerds who collect programming languages get our revenge. If you now still think of programming as something unworthy of a gentleman-engineer, well then: Fuck you very much.
I recently held a small workshop on Python at the PC^2. Here are the slides for the language introduction. I will post the slides of the project and it’s source code soon. Nonetheless my ambition for professionality in holding this workshop, I am still an undergrad student. A student who collects programming languages and has some expertise on this field, but still a student.
Now some fellow student of computer science asks whether he can have a certificate for attending this workshop. For his CV most probably. Does this guy want to ridicule himself? From the third semester he was expected to learn any arbitrary programming language in approx. one week and now he wants to have a certificate which states that took a workshop, held by a fellow undergrad, in order to learn a language as simple as Python.
His request might be correlated to the fact that in germany, more attention is paid to titles and certificates than to real skills. A behaviour which certainly applies to job applications. This feels like a Dilbert Comic, or a sketch from Loriot, that I now have to hand out certificates to fellow students, so they can pimp their CV with yet another certificate. I mean, where’s the justice? Who gives me a certificate for holding such a workshop, or even certifying my expertise in the Python language? Sadly: no one. This leaves me in the tricky question how I am going to pimp my CV. A difficult question indeed.
This is as disturbing as it is ridiculous and since we recently celebrated the 85th birthday of of Loriot, whose subtle, insightful and gentle humour has still to be surpassed in germany, I have taken the time of hand crafting a certificate of attendance for this workshop I held and I will happily hand it out to every attendee who want’s to add it to his collection. I hope you will find it as artistically pleasing as informatory. Behold:
Edit: I have redone that certificate, because the photocopier had problems with the original one.
P.S.: I hope you all have one of those valuable “Yodel Diplomas”.
Apart from all the common rejoicing of Barack Obama’s election, many people are talking about the expectations the new president will have to face. Apart from our confidence towards his abilities we should also take hers into account. Michelle Obama has been portrayed several times as at least as intelligent as her husband and she will be his most beneficial and impartial supporter and consultant. Congratulations and all the best for you both.
At the moment I’m preparing a workshop for the Python programming language and thus I’m looking for interesting examples. They should be short and sweet and I already stumbled over The sieve of Erastosthenes. Unfortunately, I was a bit keen to present some advanced data structures from Python. Because of that the performance of my implementation was bad,
-
def sieve1(N):
-
primes = set()
-
numbers = set(range(2,N))
-
while numbers:
-
current_prime = min(numbers)
-
multiples = set([n for n in numbers if not n % current_prime])
-
numbers -= multiples
-
primes.add(current_prime)
-
return primes
If you are a little bit into computational complexity and python, you should spot several problems with performance:
- I’m using
min(...)which has a runtime of O(N) in the number of elements in the set. So we are doing an O(N) operation every while-loop. Not good. - The outer while-loop runs, until all numbers are removed from the set. Here some unnecessary loops might be made.
Frank pointed these problems out and I made a futile attempt at reducing the runtime cost of min() by using lists instead of sets. Since now the lists are ordered, min() can be done in O(1).
-
def sieve2(N):
-
primes = list()
-
numbers = range(2,N)
-
while numbers:
-
current_prime = min(numbers)
-
numbers = [n for n in numbers if n % current_prime]
-
primes.append(current_prime)
-
return primes
I compared these two approaches with the cProfile module, for sieves up to 100000 and got the following results:
38375 function calls in 63.917 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 63.917 63.917 :1()
1 24.233 24.233 40.626 40.626 erastosthenes.py:10(sieve1)
1 18.460 18.460 23.277 23.277 erastosthenes.py:20(sieve2)
1 0.014 0.014 63.917 63.917 erastosthenes.py:52(main)
9592 0.024 0.000 0.024 0.000 {method 'add' of 'set' objects}
9592 0.016 0.000 0.016 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
19184 21.163 0.001 21.163 0.001 {min}
2 0.007 0.004 0.007 0.004 {range}
We can already see a speedup of approximately 50% from sieve1 to sieve2 but Frank then proposed an even faster approach. It uses an array of boolean values, whose indices represent the corresponding numbers. If ‘x’ is prime, the value at that position in the array is True. The algorithm now sweeps over the array and looks for already found prime numbers up to sqrt(N), if a number is marked as prime (i.e. array field is set to true) we mark all it’s multipliers as not prime. This can be done easily with a second for-loop. The array is initialized with all values as True and we start with 2, mark all even numbers as non-prime and go to 3. Now 3 is found to be prime and all it’s multipliers are marked as non-prime, then 4 is found as non-primed and skipped,… and this is continued up to sqrt(N).
At first I could not grasp why we only need to look until sqrt(N). But consider that we have reached sqrt(N), and marked all non-prime numbers according to our algorithm. Frank now told me boldly that at this point there are only correctly marked primes left in the array above sqrt(N) and up to N. This is true, even if it’s not obvious at first. But consider the following: every non-prime number greater than sqrt(N) can be factorized into two primes, where one prime is smaller than sqrt(N), otherwise we have a non-prime number which is greater than sqrt(N)*sqrt(N) = N, so it’s not in our search range. So if we have correctly found all primes up to sqrt(N) and marked all their multipliers as non-primes, only correctly marked primes greater sqrt(N) and smaller N remain.
-
from array import array
-
-
def sieve3(N):
-
numbers = array('b', [1] * N)
-
sN = int(math.sqrt(N))
-
-
for i in xrange(2,sN):
-
if numbers[i]:
-
for j in xrange(2*i, N, i):
-
numbers[j] = 0
-
-
return [i for i in xrange(2,N) if numbers[i]]
This algorithm does not need high-level data structures like linked-lists, so we tried to get the most simple array which could be found in Python and hence tried the array module. But for reference we also tried the standard lists of Python.
-
def sieve4(N):
-
numbers = [1] * N
-
sN = int(math.sqrt(N))
-
-
for i in xrange(2,sN):
-
if numbers[i]:
-
for j in xrange(2*i, N, i):
-
numbers[j] = 0
-
-
return [i for i in xrange(2,N) if numbers[i]]
These are our performance results:
38379 function calls in 98.769 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 98.769 98.769 :1()
1 37.161 37.161 60.856 60.856 erastosthenes.py:10(sieve1)
1 29.776 29.776 37.521 37.521 erastosthenes.py:20(sieve2)
1 0.211 0.211 0.211 0.211 erastosthenes.py:29(sieve3)
1 0.120 0.120 0.120 0.120 erastosthenes.py:40(sieve4)
1 0.061 0.061 98.769 98.769 erastosthenes.py:52(main)
2 0.000 0.000 0.000 0.000 {math.sqrt}
9592 0.027 0.000 0.027 0.000 {method 'add' of 'set' objects}
9592 0.017 0.000 0.017 0.000 {method 'append' of 'list' objects}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
19184 31.387 0.002 31.387 0.002 {min}
2 0.009 0.005 0.009 0.005 {range}
Now the speedup is quite gigantic, at a factor of roundabout 180. Interestingly, the standard Python lists are two times faster than the arrays provided by the array module.I must have missed the point of that module. But we wanted to go down to the bare metal and compare the performance with a C program.
Due to the fact, that all you need is an array and two for-loops, we tried to implement the algorithm in C and embed it as a module in Python, so we could make a better comparison. The most difficult part here was getting the algorithm properly wrapped and packed into a .so-library usable from Python. We saved the following source code in a file called erastomodule.c and compiled it into a .so-library for dynamic linking.
-
#include "Python.h"
-
#include <math .h>
-
#include <stdlib .h>
-
#include <string .h>
-
#include <stdio .h>
-
-
static PyObject *
-
erasto_sieve(PyObject *self, PyObject *args)
-
{
-
unsigned long N = 0;
-
unsigned char *numbers = NULL;
-
-
PyObject *primes = NULL;
-
PyObject *prime = NULL;
-
-
unsigned long i,j;
-
-
/* Parse the given parameter */
-
if (!PyArg_ParseTuple(args, "k", &N))
-
return NULL;
-
-
-
/* Initialize datastructure for sieve */
-
numbers = malloc(sizeof(unsigned char) * N);
-
memset(numbers, 1, N);
-
-
/* This is the actual sieve !!! */
-
for (i = 2; i < sqrt(N); i++) {
-
if (numbers[i]) {
-
for(j = 2*i; j < N; j+=i) {
-
numbers[j] = 0;
-
}
-
}
-
}
-
-
/* create a new PyList */
-
primes = PyList_New(0);
-
if (primes == NULL)
-
return NULL;
-
-
/* Put primes into list */
-
for(i = 2; i < N; i++) {
-
if (numbers[i]) {
-
prime = Py_BuildValue("k", i);
-
if(PyList_Append(primes, prime))
-
return NULL;
-
}
-
}
-
-
return primes;
-
}
-
-
static PyMethodDef ErastoMethods[] = {
-
{"sieve", erasto_sieve, METH_VARARGS, "Sieve of Erastosthenes."},
-
{NULL, NULL, 0, NULL} /* Sentinel */
-
};
-
-
-
PyMODINIT_FUNC
-
initerasto(void) {
-
PyObject *m;
-
-
m = Py_InitModule("erasto", ErastoMethods);
-
if (m == NULL)
-
return;
-
}
Then we could import it like a normal module from Python and use the function we called erasto.sieve for our computation. The following is a comparison of sieve4 and the erasto.sieve function we implemented in C. Again we have a speedup of roundabout 180, resulting in a total speedup of roundabout 32400 when compared to my initial approach.
6 function calls in 0.149 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.149 0.149 :1()
1 0.126 0.126 0.126 0.126 erastosthenes.py:40(sieve4)
1 0.017 0.017 0.149 0.149 erastosthenes.py:52(main)
1 0.006 0.006 0.006 0.006 {erasto.sieve}
1 0.000 0.000 0.000 0.000 {math.sqrt}
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
The conclusion should be clear:
- Think twice about your algorithm
- Profile mercilessly
- And port expensive functions to C
Happy optimizing!
I like to use gVim for writing. It’s great, as soon as you’re used to it’s
inner workings. Since I was looking for a decent tool to write blogposts I
have also taken a look at plugins for vim. I’m momentarily using
Vimpress
to write this post. Let’s see if it works.
At the moment clamd (Packet clamav-daemon) in Debian Etch has a bug which lets it hang at some random point during it’s reload of the virus-database.
Bug #454587 — clamav-daemon: Clamav hangs checking database
So far one temporal cure is the completely purge and reinstall the clamav-packages. Also be sure to delete the directory containing the virus-database.
Another suggestion is to install clamav from [debian-volatile](http://www.debian.org/volatile/ “Debian Volatile”), but unfortunately there is no volatile for Etch and thus manually backporting is the best and cleanest solution to the problem. It works quite splendid and goes like this:
1. Add a source-line for volatile to your /etc/apt/sources.list:#
deb-src http://volatile.debian.org/debian-volatile sarge/volatile main contrib non-free
2. Update your apt-database
apt-get update
3. Install dependencies for building clamav-daemon:
apt-get build-dep clamav-daemon
4. Fetch the sources for clamav-daemon into a directory of your choice (I chose: /usr/src/).
apt-get source clamav-daemon
5. By now you should have a directory containing the complete clamav sources (including the sources for clamav-daemon). Change into that directory and start the whole build-process by issuing
dpkg-buildpackage -uc -us -rfakeroot -nc
6. As soon as the build is complete you can go one directory higher to find a whole bunch of clamav packages built from the sources, including the clamav-daemon package. You can now install the necessary packages via:
dpkg -i
7. Enjoy.
This howto is quite generic and should work for any other package you might want to backport to Etch.
As the release date of the seventh and last book of the “Harry Potter” series is getting closer, the most exciting question is not: “Will Voldemort be defeated?”, no it’s mostly obvious that Voldemort will be defeated, the really important question, is: “Is Severus Snape good or evil”. There are many theories out on the net, debating over different facts, theories and hypothetic ideas regarding his choice between good and evil, but in my opinion there is a third option Snape can take.
Read More
Since last Saturday I’m the proud owner of “das Kochbuch für Geeks” (en: “the Cookbook for Geeks”). I stumbled upon it, while browsing the O’Reilly Shelf at my favourite Bookstore.

The geeks Cookbook at Oreilly”
I really have to say: this book is “straight to the point”, its teh *definitive* guide for every noob in the kitchen and
even some old pro like me, can get something out of it. It contains a wide range of recipes, from fast to sophisticated, and boots some extremely valuable web-references, a real bonus. And even more, instead of just offering statically linked recipes like traditional cookbooks, this one sports modular recipes and a more pattern-based approach to cooking than I’ve ever seen.
Hopefully there is an english version out too, and for all who speak german: go hack the kitchen.
The more I use Python, the more it becomes my favourite Programming Language. Two days ago I started learning 3D-Programming with OpenGL.
The Python bindings proved to be fast and well documented and everything was quite nice and easy. But as I’m taking a course on 3D-Programming at University (called Computergraphics 2) I was forced to port all 3 Assignments already done in Python to JOGL. And it proved to be more of a pain in the ass than I had expected. Just compare this lines of Java:
float light0_position[] = { 2.0f, 5.0f, 1.0f, 1.0f };
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light0_position, 0);
whit this line of Python:
glLightfv(GL_LIGHT0, GL_POSITION, (1.0, 1.0, 1.0))
Do you recognize the significant reduction of namespace-clutterage in Python. There’s no
`gl.glSomeFunction` just `glSomeFunction`. Less is more, I do say. Thats due to Pythons ingenious
System of importing things into the local namespace. Sure, you have to be careful, but for things like OpenGl it’s
dead useful and you do not need to fear name-collisions: OpenGL origins from C, which is totally namespace-ignorant, thus
everything carries an unique identifier. This is almost obvious when you take a look at constants and functions: its like the
namespace was pulled into the name itself.
The usefulness of namespaces arises from the possibility that you can load stuff from one namespace into yours and thus omit
the necessity of prefixing things with the considered namespace. Java itself is ignorant regarding Module-Functions. Either you
use Object-Methods or Class-Methods and hence you need to prefix those with the Object or Class.
What bothers me a little is the fact that the JOGL-Developer did not try to port the OpenGL-API a little more conveniently to Java.
On one Hand they could have stripped all the Class-Constants of the GL-Class from their GL thus transforming a `GL.GL_SOME_CONSTANT`
to just `GL.SOME_CONSTANT` and secondary they could have done this to the gl-Objects too, and (I think you are already guessing it)
transforming `gl.glSomeFunction` to just `gl.someFunction`.
And by the way, the PythonOpenGL-API-Reference is way better than the JOGL-Reference.
That’s the rant for today. I will need to find a way to get comfortable with JOGL, since regarding my course I will have no other choice.
Cruel World!
At the moment I’m at a most painful taskt of converting different Java types into byte-array for sending over the network.
I need to remember that Java stores everything in a 2complement notation.
But to handle all that stuff I’ve written my own Byte-O-Rama Class in Java. It’s a shit that Java isn’t even able to encode
its basic data-types into byte[] in a simple and convenient manner. I don’t talk ByteBuffers/writers and stupid stuff i talk
byte[] barr = (byte[]) intValue; Plain and simple Type-Conversion. Shouldn’t even be explicit. But since XML is overhyped in Java
no one seems to be concerned that anybody out there might use playn byte[] ’s as a fast, overhead-free Method to serialize his objects.
Python conveniently offers this: http://www.python.org/doc/current/lib/module-struct.html
If I’ve got time and anybody bothers I will go and publish my Byte-O-Rama.
wmii-3 is my new window-manager. It’s great and I’m on it to get it modified for my needs. I think I will give the acpitools, combined with some awk, grep magic a go to display battery-info in my status-bar below.
I have chosen to abandon Kubuntu-Linux over the next weeks, but I am unsure where to switch. It would be safest to go back to Ubuntu and Gnome to have everything nice and cuddly, but I’m drifting towards the shell more and more again. I was a long-time user of WindowMaker and I only switched to Unbuntu because of curiosity over their Desktop-ideas. But at the moment I’m disappointed. At the moment everything feels sort of stuck in the Linux-Desktop-World. People try to imitate the big Players instead of using their own heads. Distributions like Fedora or (K)Ubuntu or SuSE have an immense overhead of background-daemons, which slow systems down way too much. It’s like losing control to me so I’m going to switch to something colesterol-free.
My first thought was Debian, but I don’t really like it as a development-system. Unstable could be a bit fresher and I never got into their system of package-building and I always need to build some stuff by myself. So I’m going to give Arch-Linux a go on my Box. Hopefully I get all that hw-compatibility-stuff done, like acpi with battery-status and sleep and hibernate. My first impression is splendid. Arch has a good way of configuring network-profiles inclusive swichting them from the shell via ´netcfg´ I really like it. And Arch has a User Repository of Packages build by users for users. Their simpler and nonrestrictive build-system allows more people to contribute, I hope even me, as this is a main factor for me to switch. I can even recompile things for my box if I like, mplayer for example.
And since I’m more attracted to shellwork than ever I would like to try out the new and improved wmii. That Window-Tiling-Mode seems to be really promising. Normally I’m spending way too much time to arrange my Windows, or to put them in fullscreen. Now I don’t need to grab the mouse for it. Sure, I will need to learn more commands, but I think it’s worth the effort.
Hmm it’s been some time again. Well things cleared up very much since last year and I’m doing some decent progress in all of my projects right now. I even have some time to model in Blender. It’s been more than 3 years since I even touched a 3D-Modeling Program. I’ve done small projects in 3ds-Max and Softimage before but blender can quite compete whith them.
At the moment I’m doing a small project to model the Stargazer-Bridge from STNG. Here’s a WIP-picture:

Sometimes I’m a real feature creep and thus need to run the latest stuff available. Its like that in blender and yafray right now.
Due to the Orange-Project new features have been pouring into the main blender tree in the last 6 month so the Ubuntu-Package was quite outdated.
Thats how I found another gem: Blender uses Scons as a make-replacement.
Its a build-automation-tool made with python. So you can extend it with own scripts. Right now I’m adding Scons-Support into
my C++-Software for Paderkicker. There is also a Eclipse-Plugin available somewhere.
Tango Desktop Project is trying to get some
consistency into linux apps. Good Luck.
My Notebook ist back from repair. This time everything went well. When I sent it in I removed, as usually, the HDD to prevent data-loss. This confused some n00b-technicians at ASUS, who were to incompetent to solve the error AND remember that no HDD was built in. A level 2 senior enginner took over the case, repaired the LCD and put in a new HDD. Thanx a lot, thats a good backup HDD!
During the last week I experienced some rather weird I/O behaviour on Huberts one-and-only harddisk. It’s been a 3Gigs Seagate Medalist 3221; yeah it’s been. Because now this is what I call a dead hard-drive. After I witnessed another I/O crash while accessing a website hosted on hubert, I today decided to replace it.
My first approach was:
- get new hard-drive
- create identical partition structure on new drive
- copy partition data
- have fun
Did you see the important thing I missed?
Right: I missed to install the bootloader. Silly me.
But it came worse and from behind. The first three points went good. But at reboot time the BIOS of my good’ol PII/BX-Mainboard wouldn’t accept the Hitachi drive. Great. Then the old Seagate just decided to die totally and everything I got from her wer some cryptic LILO errors where everything should run smooth and shiny.
Thus I struggled to get the old drive back one more time:
- tried to get into the LILO error - useless
- tried to boot Knoppix and reinstall LILO in hda’s MBR - no good!
Knoppix prove to be unsuitable for such a task. It has a weird chroot behaviour. - tried an Ubuntu Install-CD for LILO recovery - LILO reinstallation succeeded, but at boot-time this only proved that LILO was not the source of the error.
- I also tried to reconfigure the old HD in my BIOS, since I had to change everything for my new Hitachi-drive. - no succes with this either.
Well, anyone who knows me well enough, knows also that this is not the point where the Prakti resigns, isn’t it?
But then I was lucky too: found an old 10GB IBM HTTA drive, copied the data from the hitachi onto it, ran LILO and *tadaa* Hubert is back.
As a Summary:
The most-important commands today were: tar for copying consistently (cp would result in damaged symlinks) , mke2fs, cfdisk for partitioning, chroot, and of course mount. Everything was done from a shell from within a live-system of an Ubuntu-Install-CD.
Good Fight, Good Night.
So. I moved successfully and my server Hubert moved with us. Since my old flatmates wanted Hubert disconnected asap and replaced by a hardware-router we had some severe downtime. But now we are back up and running. Weee……
My girlfriend Charlotte and I are moving to a new flat the coming weeks and this is the floorplan of it:

Today I gave Ubuntu-Linux a spin on my spare-partition. I have to say: it really rocks. I have automagically a desktop to use with great overall functionality within half an hour. Just great. I backed up my data yesterday so today I can reformat my hard-disk and get Ubunto on my main drive.
Edit: Ubuntu is up and running,… but the ACPI-Problem remains. Got to rebuild a kernel tonight.
Edit2: ACPI-Problem is done. First I tried to go without rebuilding the kernel, since Ubuntu supports the inclusion of a new dsdt over the initrd-image, but this failed. Now the third kernel is in the oven to fix the last issues with the fglrx-module for my ati-card.
Next step will be the reconfiguration of xorg to use the fglrx driver. If this is done, I’m through and everything else is just cleanup.
Turing-Train-Terminal is a Model-Railroad functioning like a Finite-State-Machine.
This might be a good provider to get a staic ip for Hubert in the future.
