GNOME programming style standards?
- From: Michael Robinson <robinson netrinsics com>
- To: gnome-devel-list gnome org
- Subject: GNOME programming style standards?
- Date: Thu, 8 Apr 1999 01:36:01 +0800 (CST)
I'm wondering if there are any style standards that GNOME code is
supposed to follow. I ask because I just found a rather embarrassing bug
in a rather embarrassing piece of code:
gnome-core/applets/asclock/dialogs.c 1999/03/27 02:30:28 1.16
===================================================================
gtk_signal_connect( GTK_OBJECT(list), "select_row", GTK_SIGNAL_FUNC(theme_selected), my_asclock);
for (cpp= themes_directories; *cpp; cpp++)
{
if((dfd = opendir(*cpp)) != NULL)
while((dp = readdir(dfd)) != NULL)
if ( dp->d_name[0]!='.' ) {
gchar *elems[2] = { filename, NULL };
strcpy(filename, *cpp);
strcat(filename, dp->d_name);
gtk_clist_append(GTK_CLIST(list), elems );
}
closedir(dfd);
}
===================================================================
A standard brace style would have prevented this bug, and a standard
indentation style would have made it obvious. A cleaner, non-coredumping
version might look something like this:
===================================================================
gtk_signal_connect( GTK_OBJECT(list), "select_row", GTK_SIGNAL_FUNC(theme_selected), my_asclock);
for (cpp= themes_directories; *cpp; cpp++)
{
if((dfd = opendir(*cpp)) != NULL)
{
while((dp = readdir(dfd)) != NULL)
{
if ( dp->d_name[0]!='.' ) {
gchar *elems[2] = { filename, NULL };
strcpy(filename, *cpp);
strcat(filename, dp->d_name);
gtk_clist_append(GTK_CLIST(list), elems );
}
}
closedir(dfd);
}
}
===================================================================
That's not the style I would use, but it is more consistent with the
rest of the code. Consistent style prevents bugs. When many programmers
are working on the same codebase, consistent style usually means a standard
of some kind.
-Michael Robinson
P.S. Here's the patch if anyone wants to apply it:
Index: gnome-core/applets/asclock/dialogs.c
RCS file: /cvs/gnome/gnome-core/applets/asclock/dialogs.c,v
retrieving revision 1.16
diff -u -r1.16 dialogs.c
--- gnome-core/applets/asclock/dialogs.c 1999/03/27 02:30:28 1.16
+++ gnome-core/applets/asclock/dialogs.c 1999/04/07 17:20:07
@@ -272,16 +272,19 @@
gtk_signal_connect( GTK_OBJECT(list), "select_row", GTK_SIGNAL_FUNC(theme_selected), my_asclock);
for (cpp= themes_directories; *cpp; cpp++)
{
-
if((dfd = opendir(*cpp)) != NULL)
+ {
while((dp = readdir(dfd)) != NULL)
+ {
if ( dp->d_name[0]!='.' ) {
- gchar *elems[2] = { filename, NULL };
- strcpy(filename, *cpp);
- strcat(filename, dp->d_name);
+ gchar *elems[2] = { filename, NULL };
+ strcpy(filename, *cpp);
+ strcat(filename, dp->d_name);
gtk_clist_append(GTK_CLIST(list), elems );
+ }
+ }
+ closedir(dfd);
}
- closedir(dfd);
}
/* show ampm toggle button */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]