Type safety
Par Benoît Dejean le samedi, 16 décembre 2006, 20:35 - GNOME - Lien permanent
Converting system-monitor to C++ helped me to spot a lot of small errors. The most common is about enum. For example, gtk_table_attach has arguments of type GtkAttachOptions. Old code used 0 which is not a valid GtkAttachOptions but doesn't yield any warning about this, not even at runtime. Thanks to g++, i've been able to fix these errors.
Moreover, C++ makes me able to write more readable code. I'm trying to convert some C code to C++, and i just can't understand what i meant.
pretty_table->app_hash = g_hash_table_new (NULL, NULL);
pretty_table->default_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
No type information. I had to read all the code to remember the purpose of these data. Ugly GUINT_TO_POINTER inside
Using C++, i simply use map<string, int> which gives me type information and type safety 