I just ported Kopete to new KDialog API and to new KPageDialog, which was done by Tobias Koenig last week. The new API is really nicer to use, you have done a great job Tobias and this helped me to adapt a lot of old code.

This new API use a philosophy called “Write once, read multiple of times.”, I use the same philosophy for some time while doing libpapillon. I will give you a case, when you read a constructor like this new KDialog(i18n("Caption"),parent, name, User1 | User2, User1, true, ...). This make sense when you first write it because you have the API documentation open in another window. Now, re-read this code 1 month later, the code will make less much sense and you will need to remember and try to guess what each parameter do. By simplicifing your API, you make your code more readable and more maintainable, not just for you but for yours followers too because we are in open source world and other people read our code.
Updated code:

KDialog *newDialog =new KDialog(parent);
newDialog->setCaption( i18n("Caption") );
newDialog->setButtons( KDialog::User1 | KDialog::User2 );
newDialog->setDefaultButton( KDialog::User1 );

Easier to read isn’t ? :)

Another philosophy should be used while designing API is make your interface ease to use and harder to misuse. In fact, that’s one item from book “Effective C++ 3rd Edition.”. Every serious C++ Programmer should have a copy of this book IMO. The goal is to reduce the complexity of your API to avoid confusion when using it, thus avoiding bugs and unexpected behavior. Also to report error at compile-time and not at runtime. I will reuse the example from the book (that I paste from my memory ;)).

Here a simple encapsulation of a Date.

class Date
{
public:
Date(int year, int month, int day);
};

What happen if someone call Date(21, 02, 1986) or Date(02, 21, 1986) ? This can lead to an unexpected behavior.

Here a good way to encapsulate Date:

struct Month
{
explicit Month(int);
};
struct Day
{
explicit Day(int);
};
struct Year
{
explicit Year(int);
};
class Date
{
public:
explicit Date(Day day, Month month, Year year);
};

By making use of keyword explicit, you avoid implicit conversion to int and compiler will generate an error if you try to use the wrong date component.

9 Comments »

Je viens de lire sur Slashdot que Stephen Hawking suggère de migrer l’humanité dans l’espace pour assurer sa survie. Tiens ça me rappelle de quoi ce truc, un certain animé Japonais du nom de “Mobile Suit Gundam”, où les habitants de la Terre et de l’Espace se livre une guerre d’indépendance des gens dans l’espace.

Moi je suis pour la migration dans l’espace de l’humanité……………

Tant qui a des robots/mech géants de combat et que j’en pilote un ;)

Source: http://science.slashdot.org/science/06/06/13/1522243.shtml

2 Comments »

Oh god been a long time since I’ve blogged and my new blog is finally on Planet KDE :)

Let give some progress about libpapillon, which is a Qt4 library I’m working on to implement Windows Live Messenger 8 protocol. Since last week, I’m working on XML schemas and WSDL description of the MSN AddressBook webservice. WLM use this web service to retrieve the multiple contact lists (Allow, Block, Reverse, Pending) and the address book (which is now the Forward List). This is still a work in progress though. I never thought that I would have fun writing those XML Schemas, it’s a good thing because it’s generally a boring and dirty work.

All those web service work will lead me to kwsdl_compiler from kode(/trunk/KDE/kdepim/kode), which should be in kdepimlibs IMO, that really some love. There is gSOAP to generate WSDL bindings but I prefer working on a WSDL compiler that generate Qt code and also cleaner code. That make me also contribute to a part of KDE that need love too.

No Comments »