The tailor
March 1st, 2009
Ok, let’s imagine you’re fed up with the GObject boilerplate code, and decide to use a mature serious language which gives easier access to classes : C++.
C++ followers will tell you how wonderful that language is, where performance with respect to both speed and space is taken very seriously. Read any document about C++ : this language has all bells and whistles, with options everywhere (do I dare saying “A real KDE!”? No, that would be trollish). Let me review some features of this both high and low level language. Performance!
Let’s begin with the most frustating issue, that of inheritance. When you override a method, by default you have done almost nothing : if your object is accessed as being from the base class, then the old method will be called. You have to use the “virtual” keyword on a method you think you’ll need to override later on. If someone else want to override and can’t modify your class, (s)he’s a two-sided toast. On the other hand, the performance!
Sigh, so you add the “virtual” keyword everywhere you think, run your program, and things just go wrong : it’s perfectly normal, you didn’t think C++. Yes, you should declare your base destructor virtual, otherwise when you try to destroy an object through its base pointer, things break, without warning. But with performance!
One more thing about inheritance, and more specifically multiple inheritance : you have to be extra careful in the diamond configuration, because you may end up with copies of data members, which may not be what you had in mind. In such a case, you will again have to use the “virtual” keyword — not where you form the diamond, but on the two branches : again, in C++ you don’t deal with inheritance when it happens, but much sooner. For performance!
The language has also nice things like constructors which get called automatically. Say you wrote an array-like class, with a constructor from integers, and you work with two arrays of integer ; at some point you want to do a comparison tab1[i] == tab2[i], but your fingers type tab1==tab2[i] — ah, you’re comparing a full array with an integer : no problem, the compiler will use the right-hand side to build an array and do a stupid comparison… isn’t it wonderful? Nonsense, but with performance! (for completeness, you saw the previous paragraphs, so I hope you guessed: there’s a keyword to avoid that problem : “explicit”.)
Another case of automatic (and unsafe) promotion is with conversion operators, but I have seen quite a few advices of not using them. I think the “explicit” keyword doesn’t apply to them (yet…).
As closing words, let me explain the link between the title and this post : Fernand Raynaud was a french humorist, and one of its most famous sketches, “Le tailleur” (the tailor) was the story of a man coming back to his tailor to complain about a bad suit. Of course, the tailor finds the suit perfect and puts the blame on his customer, who ends up admitting the suit is indeed perfect, once he has put his left shoulder a little higher, his right shoulder a little back, turned his hips a little, and raised one arm slightly…
PS: if some C++ lover wants to tell me I just don’t have the right mindset, lack the skills or whatever explanation that puts the blame on me and not the language itself : put your comment in /dev/null and read the last paragraph again, tailor!
Upgrading ubuntu…
February 21st, 2009
Today, I upgraded my parents’ computer. From ubuntu 8.04 to ubuntu 8.10. Summary : ouch.
No more keyboard in X. No more mouse in X. No more soundcard.
What happened to X? Eh, it commented the keyboard and mouse sections in xorg.conf — because now it’s magically hal-detected, so those are useless now. So useless uncommenting makes things work again.
It works, but a shiny button proposes to install nvidia drivers. Shiny, click! Let’s restart X. Uh… doesn’t start. But we get a nice dialog asking what to do. One of the choices is to reconfigure. Let’s do that. No keyboard nor mouse — again!!!???!!! Of course, it just made a configuration file without the needed sections. A dpkg-reconfigure xserver-xorg later, the situation is sane again.
Now, what about sound? lsmod | grep snd makes it clear there are no sound modules loaded. After a quick updatedb, I check where the .ko are… none for the running kernel. A google later, I learn that I need a driver package (linux-ubuntu-drivers or something like this, but with the kernel version in the name), and synaptic says it doesn’t have one for the running kernel version. Gasp!
Let’s install a newer kernel, with all we need. Reboot (I hate rebooting… that’s so… stupid). Sound is back.
The fear I have is that it will now overwrite xorg.conf regularly, and hence stop working regularly. I need to find out how to make that box just work!!!
Edit: it turns out the keyboard&mouse issues were caused by the start of X before hal… reversing their initialization order makes things work : it won’t stop working behind my back (and worse, while I’m not there to fix back).
OCaml Meeting in Grenoble
February 4th, 2009
Today I went to the Ocaml Meeting in Grenoble.
It began in the morning, but I was busy with some of my usual student-poking (several variables calculus hurts).
The first talk was David Teller, about “OCaml Batteries Included”, which seem to have gone a long way towards being both working and useful — though it doesn’t look 100% there yet. The previous sentence is a bit too pessimistic and cold : I’m pretty excited by what was explained, and it definitely looks very promising.
The second talk was Christophe Troestler about “Delimited overloading”, which may surprise some people, especially those who are used to writing “a + b” and not give it a second thought : in ocaml, you have to know “1 + 2″ is a sum of integers, but the sum of two floats will be like “1.0 +. 2.0″ (+ for integers, +. for floats). This can be pretty tedious sometimes so one of the goals of the project is to provide syntactic sugar — and more (things like automatically rewriting simply-written linear computations in an optimized and probably unreadable way).
Then Richard Jones made an impromptu talk about cross-compilation of ocaml programs for win32 on fedora, with NSIS installer. I would be interested to see what it gives on chimera projects (code mixing several languages).
After a short break, Sylvain Le Gall presented “OCaml as fast as C!”, which presented tips and tricks on having a good performance. It began with very general organization tricks, then went with more specific advices based on a recent work.
The last talk was Christophe Raffali on “Parsing technology for OCaml : from stream matching to dypgen”. He began with some simple BNF work (with the usual calculator example, explaining the different tools strengths and weaknesses. I must admit that at one point, he said “a reasonable C++ parser” — probably joking — but the shock of hearing those words together left me bewildered. He ended with an experience in parsing french grammar using dypgen… and impressive and a little crazy undertaking (if you wanted to somehow compare natural languages to computer languages, french would probably be like perl).
I had to go at the end of the last talk (unfortunately missing the spare-time-let’s-discuss part), since I had promised my wife I wouldn’t come home late. Of course, I didn’t find where I was supposed to take the bus at once and ended up coming home late anyway…
Cognitive clash
January 21st, 2009
There is a guy coming to my children’s school getting his ow children, and who regularly wears a white sweater with the following words in red on his chest : “CAN ADA” (with the zipper materializing the space).
Of course, since I know what ada is, I always smile largely at him.
Now, if I could figure out what the big red maple leaf on his back means!
Gstreamer and webkit
January 18th, 2009
Since the 5th january of this new year, gstreamer’s app plugin and library have moved from the list of “bad” plugins to the list of “base” plugins! For those who have no clue what this app plugin is about : it allows interfacing a gstreamer pipeline with another framework.
This is of no interest if you’re writing a new program : you should just use gstreamer : it’s great framework — fully threaded, but sanely hiding that fact (leaky abstractions suck… especially when one leaks the threadedness and forces threads, locks, mutexes on the rest!). If you have existing code, and you would like to add some gstreamer plumbing here and there, app is what you need!
I have begun reworking gstreamer support in ekiga : video input seems to work quite good, audio input seems to need some tweaking… and I’m stuck with audio output, where I even get crashes… hopefully some discussion with the gstreamer gurus will settle the issue too.
Aside from that, I have looked at webkit recently, and found the documentation… well, a little thin! I was interested in displaying an in-memory document, and wondered what I could do with the javascript to trigger things back in the application. I haven’t a clear view of what I want, which explains why I’ve had trouble finding serious documentation.
Saving the world one uW at a time : ekiga
December 11th, 2008
When I saw that post, I dived into the list of “affected” programs, and went “ooohhh!!!” becauseĀ ekiga was in the list.
I played the grep game in the sources, quickly found a few places where the problem applied and patched… then stumbled on a place where the fix was half-in. Why half? Because there was a #if GLIB_CHECK_VERSION(2,14,0) … #else … #endif ! After the first moment of surprise (gaping mouth), I jumped into configure.ac and saw that indeed we only require glib version 2.8.0. Ha!
I modified every applicable place to use g_timeout_add_seconds only if the right glib version is available even though I really don’t like #if code : consider the problem fixed for ekiga!
So there are a few things to know about this problem :
- one can’t just patch like this because maybe the maintainers still support an older glib : either the dep has to stay lower and #if/#else/#endif should be used, or the expected version should be raised ;
- even if grep says there’s a problem in a program, it may just be seeing the #else part of a #if GLIB_CHECK_VERSION part : there are false positives!
Thanks to Ted for the heads up!
Yet another article on a gnome program
November 30th, 2008
Some programs just don’t seem to be as widely known as they should. One of them is pretty dear to me, as I’m contributing to it : ekiga. Even among gnomers, most people don’t know about it, never used it… and are sometimes surprised it isn’t named gnomemeeting anymore!
Here is an article about “Three free tools for teleconferencing with a ‘virtual presence’” (where the ‘free’ is as-in-cheap not as-in-libre), which should help ekiga get a little more mindshare.
Dodji is my hero!
November 12th, 2008
I was craving for a way to automate a debugging session, and searching on the net only showed recent experiments for python-gdb — nothing useful yet.
As usual, I turned to #gnomefr to see if someone already knew a solution. Dodji was there and pointed me to nemiver — but not nemiver-the-standalone-gui-program : nemiver-the-lib!
Indeed, nemiver is cleanly organized as a base lib on top of which lives a gtkmm application : it is possible to write a program to automate a specific debugging session, leaving the gui aside. That isn’t 100% as simple as “scripting”, but it’s close enough!
The specific bug is still alive as I write those lines, but I feel much more powerful debugging-wise since I know I have nemiver-the-lib to turn to in case of problems!
Thanks Dodji!
Using the wrong tool for the right job
October 30th, 2008
Read this blog post on C++0x and cry with me.
This is how things work!
October 11th, 2008
What things am I talking (writing?) about?
First, of open source software : Howard Chu of openLDAP fame stumbled on ekiga and found its LDAP support too bad for his taste (to my defense I would say it didn’t work that bad with ekiga.net which itself isn’t a real LDAP
). So what do you think he did? He reported the problem. And how did he do it? He checked for already existing reports — and found them. And then? Well, then he provided nice patches, asked for help on the source organization, made better patches, got them included… and now we’re ironing out the few problems with the new improved code.
Second, since almost all LDAP clients are broken, ekiga’s LDAP code is now a good example of correct code, which others should study.
I can’t help to be sad that ekiga only came after that many softwares on the list of things he tried : it’s been around and working since years! Let me repeat : gnome has had working VoIP since years!
PS: I hadn’t blogged since long… the site has been updated and the preview just opens a blank page : I hope the layout will still look good.