[Verse-dev] Numerical IDs [R4]

Emil Brink verse-dev@blender.org
Tue, 10 Aug 2004 09:02:15 +0200 (MEST)



On Mon, 9 Aug 2004, Eskil Steenberg wrote:

> Hi!
>
> As it turns out Tuesday turns out to be a day when nothing
> interesting happens at siggraph...
>
> > how about specifying that no valid numerical ID can ever be 0 in
> > Verse?  This is true for nodes, I think (for historical reasons,
> as
> > far as I know), but could also be convenient for e.g. layers,
> method
> > groups, and methods, and all other places where things are
> assigned
> > numerical IDs.
>
> OK, here is the reason. All node references in verse use node ids,
> while in most other references verse uses names, (layers, groups,
> buffers and so on). So only for the object links does one need to be
> able to set a link to nothing. as i think about it there are a few
> other id systems where one references to ids, namely material
> fragments and vertex ids. in these cases invalid references are
> references to non existing data. (if intentional usually set to -1
> cast to uint32 or uint16) i would probably like there to be some
> mention in the spec that this id is reserved. MAX_UINT is a very
> natural number since verse ids usually starts at 0 and grows.
> However please note that having an explicit invalid id doesnt mean
> that all other values are valid.
>
> So if i where to make a change i would rather alow the node id zero,
> and use MAX_UINT32 as the reserved invalid node id.

I was not talking about *node IDs*, I was talking about _all_
numerical IDs. And I propose zero rather than MAX_UINT32 because zero
is the same regardless of the width of the IDs type. For instance, if
you have a method ID, which is a uint8, and you do this:

	void something(..., uint8 method_id, ...)
	{
		if(method_id == ~0)	/* Invalid? */
		{ ... }
	}

you've just shot yourself in the foot, since "~0" is of type int, and
the smaller type of the method_id will mean you're comparing (assu-
ming it's indeed invalid) 255 against 4294967295, which fails. Zero
does not have this problem. I think having to *repeat* the type of
the ID in a cast, like this:

	if(method_id == (uint8) ~0)

is a lot worse for everybody. I think that designing things so that
the number of casts that is required is minimized, is a good thing in
general, so I prefer reserving zero (which is, to me, a lot more
natural than MAX_UINT32 simply because of analogy with the NULL used
for pointers).

Also, I would find it ugly to use a constant containing a type name
for variables not of that type. Comparing a VNodeID variable to a
constant called MAX_UINT32 looks very wrong to me. Introducing a set
of four (or more?) MAX_xxx constants seems rather inelegant, too.

Regards,

/Emil