Re: GtkImage changes



On 29 Jun 2000, Federico Mena Quintero wrote:

> 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.

well if the setters wouldn't dup.... nah that's another thread ;)

> > 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:

yes yes i know, this is not my first day C programming (i believe at least),
so this wasn't meant as an example where you *hav* to use casts, just to
point out there are more elegant ways and:

> > use typesafety where possible, and avoid casts where possible.

is actually a general principle to follow for any good C programmer.

lokk e.g. at all the GdkWindowPrivate* casts to figure how to do it
the *wrong* way.

> And type safety is for wussies.  Just ask any Scheme hacker.
> 
> I'd better put on my asbestos suit...

i guess so ;)

> 
>   Federico
> 

---
ciaoTJ





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