[OT] A plea for aesthetics, was: Disabling up & down cursors in anEntry.



I don't wan't to step on anyones toes, but...

On Sat, 27 Nov 1999, Leonardo Zide wrote:

[snip]
>   Here's what I do:
> 

This:

> gint colorlist_key_press(GtkWidget* widget, GdkEventKey* event, gpointer
> data)
> {
>   int x = -100;
> 
>   switch (event->keyval)
>   {
>     case GDK_Up: x = cur_color - 14; break;
>     case GDK_Down: x = cur_color + 14; break;
>     case GDK_Left: x = cur_color - 1; break;
>     case GDK_Right: x = cur_color + 1; break;
>   }
> 
>   if (x != -100)
>     gtk_signal_emit_stop_by_name (GTK_OBJECT(widget),
> "key_press_event");
> 
>   return TRUE;
> }

should look like that:

gint colorlist_key_press (GtkWidget* widget,
                          GdkEventKey* event,
                          gpointer data)
{
  int x;

  switch (event->keyval)
  {
    case GDK_Up: x = cur_color - 14; break;
    case GDK_Down: x = cur_color + 14; break;
    case GDK_Left: x = cur_color - 1; break;
    case GDK_Right: x = cur_color + 1; break;
    default: gtk_signal_emit_stop_by_name (GTK_OBJECT(widget),
                                           "key_press_event"); break;
  }

  return TRUE;
}

The point is that
a) C has a language construct exactly for the situation that none of the
   switch cases matches (default), so you can avoid this "x!=magicvalue"
   trickery
b) if I'm not completely wrong, ANSI C mandates a default statement in
   switch/case constructs.
c) it is much nicer to read, you don't have to guess where that x!=100 or
   x==100 comes from.

Just my EUR0.02

Nils
-- 
Nils Philippsen / Vogelsangstrasse 115 / D-70197 Stuttgart / +49.711.6599405
nils@wombat.dialup.fht-esslingen.de / nils@fht-esslingen.de / nils@redhat.de
   The use of COBOL cripples the mind; its teaching should, therefore, be
   regarded as a criminal offence.                  -- Edsger W. Dijkstra



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]