[Xcb] no more *_new functions

Jeremy A. Kolb jkolb at brandeis.edu
Tue Oct 10 13:16:45 PDT 2006


On Tue, 10 Oct 2006, Jamey Sharp wrote:

> On Tue, Oct 10, 2006 at 03:09:55PM -0400, Jeremy A. Kolb wrote:
> > On Tue, 10 Oct 2006, Jamey Sharp wrote:
> > > On Tue, Oct 10, 2006 at 08:26:07PM +0200, Vincent Torri wrote:
> > > > Hey,
> > > 
> > > Hi, Vincent!
> > 
> > Hi Jamey!
> 
> Hi Jeremy!
> 
> > > Yes, the _new functions are no longer useful since XID types are just
> > > typedef'd integers now. Instead, just call xcb_generate_id, which has
> > > been moved to xcb.h.
> > 
> > I kind of liked seeing the type names in there.  It's less error prone and 
> > I think the user would be less likely to use an xid w/o initializing 
> > it first.
> 
> Those are interesting arguments, but I don't quite understand them.
> 
> How is it less error-prone to call xcb_window_new rather than
> xcb_generate_id? The former just calls the latter, and their type
> signatures are identical. Since we no longer have compile-time type
> checking here, I'd think it would be confusing that you can call
> xcb_window_new and pass the result to xcb_open_font, even though doing
> so would produce no errors at run-time.
> 
> Why is xcb_generate_id less likely to induce programmers to initialize
> their variables than xcb_window_new? A decent compiler will catch such
> errors anyway...
> 
> --Jamey
> 

Hi Jamey,

Let's say you have function foo(xid window);

I think it makes more sense to have

xcb_window_new(win)
foo(win)

than

xcb_generate_id(win)
foo(win)

because

With the xcb_generate_id it would be easier for a newb to go "oh it 
accepts a window. I'll do foo(win)" and totally miss that he has to 
initialize it.

xcb_generate_id works but if we use xcb_xidtype_new it stands out a little 
more and the user might see it and go 'holy crap i need to initialize this 
object before i use it'.  It might also map well to a higher level 
language port of xcb.  Anyway, it's more of a hint to the user.

Jeremy



More information about the Xcb mailing list