Re: GtkImage changes



Tim Janik <timj@gtk.org> writes:

> > Uh, I was thinking of
> > 
> > 	typedef struct {
> > 		GtkWidget parent;
> > 	
> > 		gpointer priv;
> > 	} GtkImage;
> > 
> > 	... plus a bunch of setters/getters for all the interesting attributes
> > 
> > which is my current favorite way of writing opaque objects :-)
> 
> and then you can't access internals from derived widgets.

Which is not an issue, since accessing the internals from derived
widgets {c,sh}ould be considered broken.  That's why you should
provide setters/getters for all interesting fields.

> btw, if you really need to make fields opaque, what's wrong
> with:
> 
> typedef struct _GtkWidgetPrivate GtkWidgetPrivate;
> typedef struct {
>   GtkObject parent_instance;
>   
>   GtkWidgetPrivate *private;
> } GtkWidget;
> 
> and then put
> 
> strcut _GtkWidgetPrivate {
>   gint my_really_private_pr0n_field;
> };
> 
> into your *.c file?
> 
> use typesafety where possible, and avoid casts where possible.

Look, ma, no casts:

	foo.h:

		typedef struct {
			GtkWidget parent;
			gpointer priv;
		} Foo;

	foo.c:

		typedef struct {
			three little monkeys querying an interface;
		} FooPrivate;

		void
		foo_function (Foo *foo)
		{
			FooPrivate *priv;

			g_return_if_fail (foo != NULL);
			g_return_if_fail (IS_FOO (foo));

			priv = foo->priv;

			priv->squawk = 42;
		}

Not even compiler warnings, since foo->priv is a void *.

And type safety is not an issue.  You know priv is what you made it to
be.

And type safety is for wussies.  Just ask any Scheme hacker.

I'd better put on my asbestos suit...

  Federico




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