About error handling
February 4th, 2008
I was pretty interested by this blog post, because that’s something I have been pretty annoyed with lately.
I’m not discussing just g_malloc and OOM issues there, but more generally error handling. There are several ways to deal with them, but they mostly all fall short somewhere.
There is a first scheme, let’s call it the GError scheme, which looks like this:
result = do_foo (arg1, …, argN, &error);
this is pretty nice, and can allow displaying errors to the user pretty readily, but the error is generally a complex type, so one has to some code to write them, and using them isn’t straightforward. For example, you generally see in the api that you’re getting an error, but not exactly which…
There is a second, which I don’t exactly know how to name, and which looks like this:
error = do_foo (arg1, …, argN, &result);
that one I find nicer : generally the error isn’t some complex type, but an enumeration, with an ALL_OK somewhere and a few ERROR_FOO, ERROR_BAR, etc — so you really know what you’re getting, and you have a real chance to be able to deal with it.
A third scheme requires the result to have special types — special in that there are error cases embedded in them. Typical examples are functions which return a NULL pointer on error, or how cairo does things, with a more general error handling (basically, the result object has some kind of get_error_condition which gives something like the enum of the second scheme). That is pretty much the best option in my opinion, even if that cannot always be readily done.
Finally, there are exceptions, which are pretty special in that a few languages have special support for them. I find them the worse of the lot. They’re much like the first scheme : they’re generally complex types. But they don’t even have the decency to turn up in the api, even in otherwise sane languages! For example, even in a language like Ocaml, you end up with :
# List.find;;
- : (’a -> bool) -> ‘a list -> ‘a =
# List.find (fun a -> (a=2)) [1;3;5];;
Exception: Not_found.
Gasp! I was promised a function with an api, and the exception wasn’t even visible! That is already pretty bad in Ocaml where you don’t manage memory, but reading any C++ documentation about how to handle exceptions and avoid leaks is… a very interesting read, in a way.
Distributions & stable releases
January 29th, 2008
Sebastien, I see no problem if distributions don’t update stable releases that fast : let them do what they want.
I see issues when they point bug-buddy or any type of automatic bug reporter directly to upstream bugzilla, then decide not to upgrade. Because that means even if upstream fixes things, they can still get a huge number of bug reports because of that choice they didn’t make.
A prime example of that is bug #359655, for which we got duplicates by the hundreds. We had a hard time fixing it, but even when it was, we still were drowned by the bug reports afterwards because ubuntu didn’t deem wise to upload the fix.
Let distributions both make decisions and assume them!
Ekiga is slowly coming
January 26th, 2008
Well, more precisely : it’s slowly coming from my end : other areas are progressing pretty nicely, with interesting new features soon to come.
Most of the main structures are in place, and the work is now to build little code stubs to link all of it : it should now be possible to fix some long-standing issues like the video preview still running while out-of-call and hidden, or inhibiting the screen saver during a call and reenabling afterwards… it should also be possible to re-enable some previously working features like avahi presence publishing.
There are still important main structures which needs some engine-ing, like accounts or the text chat. I already have code for the later, but need to rework it in light of recent changes I made elsewhere : the code should be much shorter now I factored out the needed features…
Things would happen faster if I didn’t happen to care about my students…
Cooling the heated discussion
November 27th, 2007
I’ll just try to make no link to others’ blogs, and cite no name.
First of all : an election is a time to discuss. And discussion can get heated. Don’t ask people to shut up or retract. Democracy is all about letting people speak…
Contrary to what someone proposed, fists are for beasts. This was a very wrong proposition!
Insults are wrong and rude. Even if they end by “:” and an explanation why.
I really don’t like the form of the starting post, but I agree with the point.
I have contributed to ekiga since a long time. I have read planet gnome since a long time. Most of my open source work was behind the scene, playing with the code, I was only visible on #ekiga and #gnomefr.
Then earlier this year (as a teacher I count years from august-september…), I decided it would probably worth it making myself more publicly known. I added #gnome-hackers to my auto-joined channels. I decided to request an @gnome.org mail address, created a blog on blogs.gnome.org… and tried to get added to the planet to join the choir (end of august).
And this is where things were tricky : how does one get added to that community planet? One name. Let’s ask. No answer. Let’s try to get him on irc. Hard : the earth isn’t flat and we don’t live on the same side. I’m told my blog is just opened, I should blog some time, then I’ll get added. One the one hand, it makes sense — on the other while the blog is new, I am not.
Refresh planet.gnome.org next morning : eh, some guy just got added : he just blogged once six months earlier and his second post, “Thanks” is on the planet. And he doesn’t seem to be a long-time gnomer.
I’m not saying adding him was wrong : being a welcoming community is important. But
why does a oldie like me have to go through a longer process?
Ooohhh… someone complains about planet.gnome on the foundation list… the board takes notice of the problem, puts out a politically-correct statement : things will move. My blog gets added end of october.
Did I mention my first post on the foundation-list was to complain loudly about proposing to extend the term of the *current* board by six months?
I get the impression that the community is broken in two camps (”broken” fits) :
- friends, which don’t see the problem, because for them the answers are always fast and timely ;
- the others, which do see the problem
That being said, I do want to acknowledge that we want to get help from everyone. Kicking someone out is just wrong.
There isn’t just a person problem : there’s an organisation problem. Nobody should have been able to get a nepotist grip on anything in the first place. Hell, would I have done better !?
Years ago, when Damien decided to give me access to the then-cvs of then-gnomemeeting, it took a very long time. This very year, when Damien & myself decided Mathias needed access to the now-svn of now-ekiga, it took a very long time during which he had to go through us to get his work in — I so feared we would lose him on that!
To have a blog on blogs.gnome.org, you first need to get an @gnome.org alias, for which you first have to … for which you first have to… In case you don’t know, we french coined the “bureaucratie” word which got “bureaucracy” the other side of the Channel and beyond : I can tell you for sure this is one!
On the other hand, something didn’t look right in wormux. I got the svn sources, made a patch, uploaded it to gna! For this, I had to create an account there : five minutes. The developpers committed, but kept the bug open because there were other similar things that could be done elsewhere. Eh, I know how to do that! Second patch. I get proposed an svn account to commit myself [Yes, after only two patches, but they were both ready-to-commit, and I was known as an ekiga developper already : that helps
] (discussion translated from french) :
- Eh guys, you should commit right now, the patch will get rotten before I…
- If you upload your ssh key, then you’re one hour away from committing — sorry, it’s a cron we can’t go faster.
- !!!!!!!!!
I committed within an hour after I uploaded my ssh key. Gasp.
I hope I managed to write something higher than some of the things I have read on the gnome planet those last hours!
OCaml, eclipse, ekiga…
November 17th, 2007
Last time I blogged about how python saved my day, but I didn’t really enjoy the experience : by itself, the language will discover huge mistakes only when hitting the right code path. Yes, I know : “Use unit testing!”. Right. For me unit testing is about checking corner cases are handled correctly, not about checking the code even makes sense. It’s about making something 90% correct go 99.999% correct.
So I turned again to a stronger language, one which will tell me exactly how wrong my code is (and where and why) the minute I write it : ocaml.
Of course, as I said last time, it lacks decent XML support : it does have simple parsers, but nothing serious : if you load an XML file, you can’t really edit it in-place. You have to save by yourself, which means if you parse something like <foo detail='bar'>...</foo>… but only know about the foo tag without detail, then you will save without the unsupported attribute and same problem if there’s an unsupported child.
Still, as I have hope that things will improve (well, I may even have a hand in it), I went forward.
I even discovered OcaIDE, an eclipse plugin for OCaml, which works pretty well with gcj, but with a pretty annoying performance issue on the completion — which disappears with sun’s virtual machine (problem reported).
Together with the new ocamlbuild tool, which takes care of most of the dependency tracking, things went fast : I have almost duplicated the python features I already had. A little because I factored things a little differently, but mostly because I was discovering eclipse, ocamlide and ocamlbuild (with python I was just discovering the specific modules I was using : I knew emacs already, and the module system).
Of course, things would go faster if I stopped requesting assignments from my students every week… which means reading and annotating like crazy.
I also brought back to life the skeleton of ekiga’s future call history, which had been compiled out since a few weeks… and I learnt I would have to rewrite the evolution-data-server at least partially. Sigh.
Better workflow : saved by a rampant
November 6th, 2007
My last post about the sorry state of my workflow triggered a few answers :
many thanks!
The most interesting was to use a database : after all, organizing data is
the whole point of databases, doesn’t it?
So I looked around for what is available to make my life easy, and found
glom (well, I had already read a few blog posts about it on planet gnome, but
never dug into it).
It turns out it’s not in debian (and probably won’t anytime soon : there is a
package in the works since so long…), and that its dependencies aren’t up to
date anyway.
So I chased them one by one, using the sources and debian’s .diff.gz to get
updated packages (I hate using ‘make install’) — as an aside, that reminded
me a lot about the early days of gnome. Sigh. I was so patient at that time.
Finally, I could compile and install glom (using ubuntu’s .diff.gz to get nice
packages this time, since debian lacked the equivalent). It even ran, but it
was a little too unstable for my taste : starting and stopping the database
gave issues, it didn’t like my passwords, for example [yes, I reported].
These stability issues mean I can’t use it for work, but I’m still pretty
impressed by what I saw, and I’ll have to find a problem to solve with. If
said problem doesn’t exist, I’ll just invent it
.
Using a database directly didn’t look as promising, so I left that option out.
Embedding the tags into my files directly definitely is out too : it’s gross,
and would assume I only have text files, where it’s easy to embed things. This
is the case with texmacs files, as are most of the things I use (giac/xcas,
maxima, gnuplot, C, C++, …), but what if I want to associate an image to an
exercise? or anything binary-based where embedding text and using grep isn’t that easy?
So I went for the solution where I store the metadata separately, in helper
files. And I stored the metadata as XML files, since that’s both easy to use, and extensible.
At first, I tried using C+libxml2. The first tests went pretty well, and things looked
pretty promising. Then I typed something like :
$ ./exo-tag-create “Réduction d’endomorphismes”
12
$ ./exo-tag-text 12
<partial garbage>
I tried to use a few magical functions (g_locale_to_utf8, for instance) to
sanitize my strings before I feed them to libxml2, but couldn’t get things
right. I just hate when a stupid little thing completely unrelated to the
problem at hand gets in the way — I didn’t expect any issue since my env has
“LANG=fr_FR.UTF-8″… so things should have just worked!
When a problem doesn’t surrender fast enough using an approach, the best is
generally to try another one. I dug to see if ocaml had gained a decent XML
lib since last time I searched for one… unfortunately, no (such a shame for
such a beautiful and powerful language!), and I didn’t want to dust off the code
I wrote last year for babili.
Next try : apt-cache search python | grep xml
The debian description of python-lxml mentioned it used unicode strings, so I
settled on it, and quickly tried to build a pair of scripts to test if my
little problem still applied : no. Perfect!
So I wrote a first series of scripts to manage tags and then another to
manage items. Since there was too much code duplication, I refactored things.
Then I tried to write gtk+ helpers using the refactored code : easy. Then little
scripts to split my existing texmacs files into chunks, and join chunks into
a new document. I don’t have all I need yet, but it takes a pretty exciting
shape already.
Python saved me. It made things pretty easy, but I can’t help to
dislike it nonetheless : that language is too weakly typed for my taste (even
if using pychecker helps to alleviate this). I really prefer more serious
languages like eiffel or ocaml (the later leads to terser code : type
inference rules!).
In a few months (or years, if necessary), I’ll be able to push my data to a nice
database. And if so, I really look forward to using glom.
Devices, I always come back to you
October 28th, 2007
Past : itched by gnomemeeting
Years ago, I was discovering a wonderful program : gnomemeeting. It already made it possible to make calls with both audio and video (that was years ago and some projects still struggle to do things half as good!). And I happened to have two video devices available : a USB webcam, and a IEEE1394/FireWire/iLink/whatever-the-vendor-felt-would-sell-more DV camcoder.
And this is where things got tricky. Pwlib, the library which gnomemeeting used to handle devices had a PVideoInputDevice class (it’s C++), and several implementations of it — moreover it had implementations for both my devices! That was really a feat :
- at the time the kernel had very, very poor device support for video — but both had a driver
- someone else already added support to pwlib!
The big issue was that switching from one device to another required recompiling the whole of pwlib with a different option. Ouch.
So here was the itch. And this one turned me from a libre software user to a libre software developper : I decided I would make it possible to switch them at runtime — which mostly meant changing the structure from a #ifdef tree to a nice class tree, with dynamic loading and a simple listing ability. Of course, C++ made it a pain because I had to track each and every method to add the “virtual” keyword all over, but I’ll rant about C++ another day (and perhaps say also a good thing or two about it — three if Dodji hits me hard enough).
Present : pretty good, but still
This initial contribution prompted other contributions, which triggered other contributions, which… This is why ekiga (gnomemeeting’s new name) has a very good device support these days, through the use of plugins, which exist for various platforms (GNU, *BSD, win32, …).
But those plugins themselves are all based directly on platform-specific API. We have ALSA, OSS, V4L, V4L2, AVC and DC, just to name those which work on GNU/Linux based systems. Whenever some incompatibility happens, we have to fix it ourselves for ourselves : it’s all about us.
And this is why I’m not satisfied. I would rather see pwlib have support for a single portable audio and/or video framework, which would be shared by as many projects as possible. That would have huge advantages : first the user interface would be simpler (we currently make the user choose among a list of badly-named managers before they choose the device) and then both problems and solutions would be shared on many shoulders.
Notice that this isn’t pwlib bashing : the current organisation made sense, since there was no such framework at that time. Things are different now : there are different choices — and possibly we can take several of them at first before picking the most suitable.
Future : choices
Using portaudio
Portaudio is a nice portable audio framework — we are almost using it already. The positive part of ‘almost’ is that we do have a plugin. The negative part of ‘almost’ is that it doesn’t work correctly yet. Let me admit that I’m a little stuck.
Using GStreamer
This one I don’t think I need to link to here : all must have heard about it already. This is a wonderful framework. Does audio and video. Will probably do what ekiga needs network-wise at some point in the future. Unfortunately, it is wonderful as long as you manage all of your data with it — things get more difficult if you just want to use it partly.
Let me get into more details here : my original plan was to write device plugins for pwlib, then as time go by use it more and more up the data streams until it’s everywhere. Yes, that framework makes me giggle, so I would like it used more.
But the problem I hit is that to do that, you need to do some plumbering between the GStreamer framework and pwlib’s own stream framework. And this isn’t easy. I do have some experimental code, both for audio and video, but they’re hackish ; the real solution would be to fix this bug, which is precisely about having bridge elements to allow plumbering (not just to pwlib, but to whatever other framework you may want to throw at it).
Of course, I didn’t just report issues, I also tried to report with minimal examples showing the issues, and even some patches. Eh, the goal is to share after all. Both code and problems!
Conclusion
So as you can see, contributing to device support is a very good way to start hacking on a project : if anyone wants to lend a hand — please do!
And don’t think you’ll always be stuck with devices : it’s just that you’ll always come back to them ![]()
My workflow really needs serious love
October 26th, 2007
Part of my work consists of having loads of exercises, and being able to come up with short lists of them which fit some criteria ; like “can use numeric series, cannot use function series, can use topology, cannot use endomorphism reduction”…
My current work organization is to have a few lists of those, organized in chapters, and hand-picking the matching ones from there. It does work, but is quite long and painful.
So I’m looking for some kind of tagging system to help me with it.
The first solution I came up with was : put each exercise(+optional solution[s]) in a little file and try to use emblems in a file browser. Unfortunately, that meant :
- a huge number of files to create
- create emblems
- right-click each of the numerous files to add the right emblems
- I don’t know exactly how to search on multiple criteria
- how does one backup this?!
A better solution I’m considering is : put each exercise(+optional solution[s]) in a little file, then create a structured file to associate tags to each file. If I go for the “filename tag1 … tagN” solution, then searching is just a grep away. Combine with some awk-fu and some scripting and I can probably automate the creation of a document with all exercises. Backup is easy. Pending issues:
- still requires creating a huge lot of files
- in which format do I store the exercises(+optional solution[s]) so I can easily automate the merging?
- in which format do I write the exercises(+optional solution[s]) so it’s easy to write&edit afterwards?
I’m currently using the very very good texmacs to write all my documents, so it would be nice to be able to do something with it. It will be even better if I manage to get two documents : one with the questions for the students, and one with solutions for my poor head…
Getting a refund for software licenses
October 12th, 2007
Some of you may have noticed that since I had bought a new laptop, that meant that I either accepted a set of software licenses, or refused and asked for a refund.
In fact, I even asked for a refund even before I bought. And since that wasn’t enough to make them bulge, I made it clear to the selling company that I really meant it with a nice official (paper) letter afterwards, giving them 15 days to comply.
A nice mail thread followed, during which they could propose either 20€ and nothing on the bill, or go through ASUS and get 25€, but only if I sent them the laptop (paying forth and back trip!) and saw the warranty voided. For some reason, I met neither with enthusiasm.
When the 15 days were gone, I sent them a mail to tell them that probably meant a trial, but still wrote to an official organization (the DGCCRF) as a last chance for them.
They were suddenly able to make the following proposition : 20€, with a line in the bill. Which leaves me wondering if they’re selling at a loss, since it’s 25€ through ASUS. But at least, they finally acknowledged they had to detail their bills.
I don’t know what I am going to do now, but things seem to take a better shape somehow.
When computer science could help students with mathematics
October 2nd, 2007
I spent hours trying to figure out what my students were trying to prove — I knew the questions, but the answers made little sense.
The problem is that they’re focused on doing computations, and for that they use letters, letters, letters… none of them they introduce before use!
Worse, sometimes they will fix, say $x>0$, then later on consider a function $x\mapsto f(x)$… which means a collision!
Even worse, since they’re just toying with letters, they don’t have issues applying a function defined on reals numbers to a complex number or a high-dimensional matrix…
So my current job is to beat some sense into them and have them define things before use, and define as little as possible. This way, when they’ll have the real, serious test at the end of the year, they won’t have ridiculously low marks just because their proofs don’t look like proofs.
If only they had more computer science to do with me, I could try to push them in front of languages which won’t let them use variables without declarations, won’t let them apply operations if they don’t make sense, and won’t let them reuse the same variable in the scope of another!
But I only have them for a little maple work (sigh… unfortunately, xcas or maxima aren’t an option for them), and they have a very hard time just writing a simple function to loop over an array, so I can hardly make use of a compiler to suffer instead of me : I’ll have to do all the complaining myself.