Writing APIs the Ruby way
May 22nd, 2007Recently I’ve been working on some library classes for the KDE4 Games module. Firstly a high score table system and more recently extending Mauricio Piacentini’s KThemeSelector to use KNewStuff2 and make it usable by any game in the module.
This is the first time I’ve worked on any sort public API so it was interesting to see the way I do it compared to the rest of KDE/Qt.
Now I’ve never actually used Ruby. All I’ve done is read a few articles on it and look at a tutorial or two. I can’t remember anything substantial about the language but the one thing that has stuck in my mind about it is it’s design philosophy that is most often talked about. That is the way that it caters for the majority of uses by default. By that I mean most classes that are ever written will, for 90% of the time, only be used in one specific way. With maybe a few lines of code that are the same every time the class is used. It is only 10% of the time that the class is used in a way that is out of the ordinary. Because of this rule, API should be tailored towards making it really easy for the 90% of people who only want to do basic things.
Now this sounds like very good philosophy to have when writing an API which is providing an easy way to implement a highscore table or a theme loader. Most tasks should be possible in three lines of code and only the unusual tasks (like custom score fields or loading themes from a different directory) should require more. I think I achieved that with KScoreDialog.
Incidentally, hello PlanetKDE.org! I’m Matt Williams (milliams on IRC/SVN). I’ve been actively hacking KDE for about 6 months (though I’ve been helping out with various other bits for a while before that) now and I’m currently working on kdegames and doing a little bit of work on Plasma.

Home