Archive for the ‘Programming’ Category

Object oriented PHP - a disappointment

Thursday, July 31st, 2008

It’s no news that PHP supports objects, and has been for a while now. Even if objects in PHP, before version 5, internally is represented as an array, with the result that all methods and properties are public, this was rapidly accepted and used by the community. As of PHP 5 the Zend Engine was rewritten and got a “robust and extensible object model”. This sounds good and at least it got my hopes up for OOP in PHP. It doesn’t really matter but I can mention that I’m currently running Apache 2.2.9 and PHP 5.2.6 on Windows XP, that’s the versions used for running the code below.

Unfortunately I’ve not been able to really try the OOP support in PHP 5 until now and I must say that I’m not impressed this far. Sure, PHP now internally supports a more resource saving object model which also offers common OOP functionality but you can’t still use it in a real OOP manner. For example there is no real support for overriding a method or extending an interface like in the code below.

I suggest that PHP should be divided into two separate branches, “PHP procedural” and “object oriented PHP”. The latter would benefit if it was separated and the focus changed to fit larger projects where OOP really can ease the development. This is not possible today.

I also feel that I can’t post this without mentioning the experimental PHP extension “Object overloading” and this pretty much applies to overloading in PHP 5 as well. In PHP overloading ‘provides means to dynamically “create” members and methods’. Consider it an extension of variable variables. I can honestly not see the benefits of such an extension. It produces code that is harder to read, debug and maintain. Personally I think it’s a very ugly solution (due to a poor design) and not necessary when developing web applications.

class O {}

interface S {
public function a(O $var);
}

interface E extends S {
public function a();
}

class MyS extends O implements S {}
class MyE extends MyS implements E {}

I end this by saying that I hope that I’ll be proved wrong.

FreeDB to MySQL parser

Friday, March 17th, 2006

Ever got curious on something and then you’re unable to let it go until you’ve tried it out? Thought so. For me it started with the extracting of the FreeDB archive. What a beast! You start with a small innocent tar.bz2 archive of about 440 Mb. Extract the bz2 archive and you get something quite big, about 3.2 Gb tar archive, and it is now that you start thinking about the nagging about reading the FAQ before extracting. What a newbie can’t extract a simple archive?! Then I ran out of inodes on my partition… Cute.

The fact that the database contains almost 2 million files (2,000,000) is really a problem. If you don’t run out of disc space due to the overhead you’ll run out of inodes like I did. I was frankly surprised when the disc was full, I had 25 Gb free when I started and I had plenty of space left when it stoped. This was a partition using FAT32. Now I had a peek at the FAQ

Next try, extracting to a partition using ext2, and this time I didn’t ran out of something. Thus it took my old disc several hours to extract all files. Now then? Here I was with a directory wasting about 7.4 Gb of disc space. Why is it distributed in this way? I would prefer to have the data in a MySQL database. There are some parsers out there for those of you that want to take the easy way out, but what’s the fun with that? So I wrote my own in Java and it is now released under the GPL, read more about the Viba IT FreeDB to MySQL parser.

Now when the week-end is drawing near my tip for you is to try it out. It’s not every day you’ll have the possibility to play around with this amount of data. For your information, once parsed and imported into MySQL the disc usage for the data will only be about 1.5 Gb including indicies for all tables. Nice, huh?

Plan of open 3D game development

Tuesday, March 14th, 2006

For the last couple of days I’ve been looking around for open-source 3D engines, comparing and reading. This is an early step in my crazy plans of making an open 3D game. If the game ever will be realized is yet to be seen, but the research is very interesting though. There are a bunch of open-source 3D engines out there and the ones I’ve been looking at are Crystal Space, Irrlicht, Ogre and Panda. Since you probably don’t want to change the 3D engine in your project once on the road, you’ll have to do some research before the project is started. It isn’t easy to compare these engines, you’ll have to have good knowledge about your own project so you know your exact needs - now and in the future. It’s painful to walk in too small shoes.
Below is a table over the 3D engines mentioned above. This table is not ment to be a comparison between these 3D engines, it’s just a summary. The data was collected at mars 14th, 2006. The last column is just the number of hits on Google and thus doesn’t really say anything.

Name Version License Language Popularity
Crystal Space 0.99 LGPL C++ 274 000 Features
Irrlicht 0.14.0 zlib C++ 490 000 Features
Ogre 1.2.0 RC1 LGPL C++ 29 900 Features
Panda 1.1.0 P3PL v2.0 C++ 22 200 Features

Some of the 3d engines also have wrappers so that you can use your favorite programming language to develop software using the engine. Since the wrapper only handles the communication between the 3D engine and your code the loss in performance isn’t overwhelming. The actual loss depends in the implementation so I’ll say nothing further about that.

Do you know of another 3D engine or did I miss something? Then let me know.