[Verse-dev] Numerical IDs [R4]

Emil Brink verse-dev@blender.org
Tue, 10 Aug 2004 18:30:23 +0200


On Tue, 10 Aug 2004 17:55:07 +0300
Eskil Steenberg <eskil@obsession.se> wrote:

> Hi
> 
> > I was not talking about *node IDs*, I was talking about _all_
> > numerical IDs. 
> 
> I know, my arguing was that, its not that the way node ids work is 
> the standard way of handeling ids, Node id are the ones that are 
> different form the rest, so my arguing is that if you compani about 
> conssistency, the node ids are the ones that has to change.

Well, I'm partly complaining about consistency, it's one of my super
powers. But, I argued in the direction that I did, towards making the
value 0 reserved for all numerical IDs, because it is very handy.

> > 	if(method_id == (uint8) ~0)
> 
> I assume this was a typo, you meant:
> 
>     if(method_id == (uint8) ~1)

Um, no? That's a tilde (~) character, not a minus...

> But my main question is when would you ever need to do this test? 
> verse would never send you a value that was -1, so the variable 
> method_id wouldent ever come from verse. And the test you do does 
> not garantee that the failiure of the test means that the id is 
> valid. In other wordts the only reason for theis test is the slight 
> optimization of an early detection of a broken reference.

Hm... I wasn't thinking about broken references at all. What I was
(am) doing, in Purple, is create a method group and a bunch of methods
on my avatar. I then need to track when these have been created, and
set my internal variable holding e.g. a method ID to the value given
to me by the server.

Because I use a rather coarse "node structure has changed" internal
notification system simliar to Enough's, I need to check for multiple
changes in my callback, it is not a pure o_method_create callback.

When doing these tests, I want to make sure that I only care about
and look for changes that are not already known, to avoid doing re-
dundant string comparisons against method names, for instance. Thus,
I want to check if my local method_id variable has been set to a valid
ID already, or (if it has not) I am still waiting to learn about that
method.

I might add that a static variable in C can be guaranteed to be
initialized to 0, so I don't need to have initialization code that
first sets the ID to ~0 as I do otherwise. This, in my book, is a
huge win, since it not only shortens the code, it removes one thing
that can be forgotten and thus makes the code more robust.

> So the invalid id is never used by verse, and are not very usefull 
> in any client end either. 

I disagree. I find it very useful to be able to set an ID variable
(or structure field) to a known invalid value, to mark that I am
still waiting for the server to assign it.

> if zero was reserverd it would force  especialy host apps to have
> special code to handle this. I can agree that the cast -1 isnt that
> nice so perhaps we would like to add defines for it in verse.h

Such defines would have to include the type of value, which is not
very elegant, compared to just using zero.

> Next reason is that verse uses -1 internaly as an invalid valuee for 
> a lot of things. A change would upset a lot of things in areas where 
> you wouldent want them to change.

Hm... Yeah, I guess, but I think it's worth it to get a cleaner and more
easily used API. :)

BTW, I don't think I was officially "aware" that all-ones ("-1" as you
put it, although I find that confusing and wrong for values of an unsigned
data type so I use ~0 instead) is reserved for numerical IDs. Is it?

/Emil