Mats hosted a little competition last weekend. The main goal of the competition was to make a program which found the shortest path from . to X in a labyrinth, and the code size should be as small as possible.

My first approach was a depth-first seach algorithm, but when I ran the code on large labyrinths the algorithm took to long time. Then I tried a breadth-first search algorithm which proved much faster and stable on finding the shortest path.

Even if I did manage to get my code down to 518 bytes, I didn’t even get close to the winner, which got it down to 253 (results can be found here). You can take a look at my code here, it isn’t as advanced as the other examples shown on mats’ page but it works and finds the correct answer quickly.

My server is finally up and I started writing a little web script to unpack and move files from a local place on disk to a ftp folder. I decided to use php since it is a language i know and it is quite efficient on small programs.

I bumped into some problems installing the fileinfo resource extension when using a windows server. I used the php msi installer to install php and used the same installer to add the fileinfo extension, but the installer didn’t include all the files. You also need some extra files in the php/extras folder, these files can be found on sorcefourge. You need the magic and magic.mgc files located in the bin package.

When the extension was successfully installed I tried with a simple example to see if it would match the filetype.

$fi = new finfo(FILEINFO_MIME, 'C:\PHP\extras\magic');
echo 'filetype ' . $fi->file('e:\test.rar');

this code should print “filetype application/x-rar”, but it showed application/x-dpkg instead. The reason was that windows returns a match if the condition starts with “!”, so i had to add “\” in front of every condition that started with “!” in order to get a correct match.

example:

0    string        !<arch>\ndebian application/x-dpkg
should be:
0    string        \!<arch>\ndebian application/x-dpkg

If you don’t like to use objects you could use this code instead:

$fi = finfo_open(FILEINFO_MIME, 'C:\PHP\extras\magic');
echo 'filetype: ' . finfo_file($fi, 'e:\test.rar');

Earlier this summer I started a project where the goal was to learn more about code design. I asked different people on which code design they preferred and ended up with the mvc-pattern. My first thoughts when I read about it where that the idea was good but I couldn’t visualize how the code would be, so I decided to make a simple website using the pattern. After the website was done, I tried adding more functionality to the site, which was really easy and it made me wonder why we don’t learn stuff like this at school when we start programming. Wouldn’t it be better if people learned about different patterns and code design when they started learning about programming instead of first have to learn about programming, then have to restructure their coding styles to be more efficient/scalable ?

If you look at the advantages by a good code design the answer should be yes, but there are pros and cons to this. If the instructor choose to implement the code design in the course it means that he have to remove other topics. What topics could the instructor remove? The students have much new information to process and remember, would the code design part make them more confused or would it help them to get a better overall picture about programming?

I personally think the code design part would make the average student more confused, which again makes more students drop out. But I also think that code design is important to programming, and every programmer should think about their code design.

I’ve finally found my way to the blogging part of the Internet, which is the reason I’m starting my own blog. This blog wont have any specific content, since I’m going to use it to write down thoughts and notes on stuff i find interesting.

Time will tell how much and which content this site will be filled with.