Re: toggle_button vs check_menu_item



Havoc Pennington writes:

> It is object oriented, because a GtkCheckMenuItem and a GtkToggleButton do
> not share a common base class representing "toggleable." Your proposal
> would create a fundamental type error because it would allow you to apply
> a set_active() function to objects that cannot be toggled.

You are trying to define the API in terms of the current
implementation rather than in terms of the operations it is logically
possible to perform on objects.

Suppose the underlying implementation totally changed so that
GtkCheckMenuItem and GtkToggleButton *did* come from a common
class. Would your recommendation change? An API that one would wish
to change if the implementation changed is a badly designed API
unless there is a *very* good reason for it (and "I would have to
write a twelve line function with a switch statement in it" is not a
good reason!).

It seems to me to be beyond dispute that in an object orientated
toolkit it should be possible to write 'frobble(myobj)' for any object
for which it is possible to frobble, rather than having a host of
functions 'frobble_object_of_type_1', 'frobble_object_of_type_2',
'frobble_object_of_type_3', etc. simply because of the way the toolkit
is currently implemented. 

The 'fundamental type error' argument is spurious. One of the costs of
GTK+ being written in C is that type checking is run-time rather than
compile time. To use gtk_check_menu_item_set_active you have to do a
caste which is only checked at run time. Whatever functions we write
would have to do their own type checking. 

It all comes down to the question of whether GTK+ is an implementation
of an object orientated API or an object orientated implementation of
a non objected orientated API. 

And whether people have noticed the fuss over the incompatibilities
between 1.0 and 1.2 which are the inevitable consequence of making
choices about APIs based on the current implementation.

Choose life.

John



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