Friday, September 4, 2009

Python + HTTP + MIT + Freedom = Cenchria

Hi there ! Just… check out the little Cenchria ;)

Monday, August 17, 2009

PHP: I really can’t do that…

Hey folks ! Told you I was working hard on Kheops ? That was true :) But still… PHP team seems to make only crap, these times. See for yourself.

Well, first of all. When you have a boolean, an integer, a float, would you expect to be able to use it as an array ? Of course no, that’s got no sense ! But PHP did it !

$var = false;
var_dump($var[‘nothing here’]);

Output:
NULL

Oh, but maybe it’s actually got some logic in it. See: NULL evaluates to false in a condition. So maybe it was intended. Ok, then getting an offset of true would return something that’s true.

$var = true;
var_dump($var[‘please do it, PHP’]);

Output:
NULL

Well… No ! That was not intended, that’s a pure bug. Try it out with integers, strings, floats, and see how bad it is. This could be an undebuggable bug source…

Did you every try to use objects as array’s index ? I you did, you surely know you can’t. But that’s not a problem anymore: having a look at their documentation makes clear that they thought about it, as they created the SplObjectStorage class, that appeared in PHP 5.1.

Let’s look at this attach method. How great, I can put objects in this collection, and attach information to it. It’s a little like a Java Map. And this method is, of course, available since PHP 5.1.

But let’s have a closer look: how to get this information back ? getInfo, offsetGet… Perfect ! But, hey, see that ? They are available only from PHP 5.3

I discovered earlier today that, in fact, before PHP 5.3, the attach method took only one argument: the object. There was no way at all to add information. Thus… that was only a list… an array !

And note also that nowhere on this page we are noticed that this function changed in PHP 5.3. Damn, this is the SPL, Standard PHP Library, maybe it should be a little documented ?

 

Well, you understood it: I can’t bear PHP anymore. I’ll be waiting for the 6.0 to see what changed, and maybe readopt it. But for now, PHP is going worse and worse.

PS: PHP namespaces are horrible, you’ll soon learn to hate them.

OOP: Three reasons to use interfaces

I’ve been long wondering why I should use interfaces. Hold on, this post is going to be somewhat long ;)

Of course, there is the most commonly known fact: you can specify one interface for several implementations. A good example of this is the Java List interface, with its subclasses: ArrayList, LinkedList, Vector…

But I recently discovered two other reasons. Consider these classes I wrote a few days ago in PHP:

class Statement {
    public function __construct($query);
    public function execute(array $args);
    public function fetch();
}

class ResultSet {
    public function __construct(Statement $stmt);
    public function hasNext();
    public function next();
}

A ResultSet is created from a freshly executed Statement, taking its data from the Statement::fetch() method. But don’t you see a little design flaw here ? Doesn’t something bother you a little bit ?

Yes, you got it! We just gave the ResultSet class the right to execute a Statement, and that’s really bad!

Now guess what… we are going to use an interface to correct this design error. (changes are in bold)

interface Fetchable {
    function fetch();
}

class Statement implements Fetchable {
    public function __construct($query);
    public function execute(array $args);
    public function fetch();
}

class ResultSet {
    public function __construct(Fetchable $ftch);
    public function hasNext();
    public function next();
}

Now, our ResultSet class doesn’t have the ability to execute a Statement anymore.

This is called “Defensive Programming”, or at least it’s a bit of it. Defensive Programming is a kind of coding mindset, aiming to reduce the risk that other people, or even you, make mistake while coding. With the above example, this is done by restraining the actions your code is allowed to do.

The last reason to use I found (but I bet there are lot more), it that it will help you to perform Test Driven Development (TDD). Let’s take the above example once again. I want to test this ResultSet class. One way to test it would be to create a select statement, execute it and create a ResultSet object with it.

Ow, wow, poor database, poor testers, who will have to ensure the db is not empty, poor developer who will have less quality tests, poor…

With interfaces, however, I can create some stupid class, let’s say DummyFetchable, that would implement this interface. And simply give this class to my ResultSet: I swear, this good guy will see nothing!

class DummyFetchable implements Fetchable {
    public function fetch();
}

class ResultSetTester {
    public function testResultSet() {
        $source = new DummyFetchable();
        $rs = new ResultSet($source);
        
        … and test this out, without killing your db :)
    }
}

Hope this post has been of some use to some people :) Let’s summarize it all:

  1. one external behavior, several implementations;
  2. Defensive Programming;
  3. Unit Testing;
  4. and certainly more, please let me know :)

Wednesday, August 5, 2009

Kheops: working hard !

I have been working hard lately on Kheops… The underlying framework is mostly operational, but I guess it lacks some features… However, it already offers effective module management, localization, logging, database connectivity and so on !

I’m currently working on a little “goodie” that will speed up module development a lot ! Once this goodie is finished, sources will be available so that you can develop on this wonderfully new platform ;)

I’ll keep you posted !

Monday, July 13, 2009

Kheops: on the road again !

Kheops will be back soon. It’s being built on a stable basis, a custom, all new and re-usable web framework (yet another PHP framework…).

You can’t get it yet, but it should be soon available. Of course, as this is a new start, it does not implements features at this time, and even some parts of the structure still have to be decided.

One of the biggest question is:
”Will it use database, or rather files” ?
For now, I would tend to use files, as it proved to be a wise choice before.

What d’you think ?

Wednesday, July 8, 2009

XMind, an open source mind map designer

Hi there.

Maybe you know what is a “mind map”. If not, maybe you would be interested in it ;)
Anyway, I just laid my hands on this nice mind mapping software: XMind. It’s an open source software, based on the Eclipse platform.

Have a look at it ;)

Sunday, June 28, 2009

Test ticket for Live Writer

Ok… Live writer tells me it can handle my blog. Nice, let’s try this out.

If you see this, consider it worked ;)

Edit: Amazing so far ! Will this edit work ?
Edit2: OMG ! It works !