Internal Name Operator
by Tom Bampton · 09/07/2006 (5:03 pm) · 24 comments
There's been some discussion for a while about internal names. They were originally implemented in TGB to make GUI code a little easier to write ... but findObjectByInternalName() is long and irritating to type.
I think it was Paul Dana that suggested a new operator for referencing objects in a group by their internal name. After talking with Justin about it today for the umpteenth time, I finally got around to implementing it:

Ben mentioned that -> could be confusing to programmers used to C++. He does have a point, but is it worth worrying about ? If so, what would be a better operator ? All I can think of is "#", ".." and ".>" ... but they all feel a bit strange.
I think it was Paul Dana that suggested a new operator for referencing objects in a group by their internal name. After talking with Justin about it today for the umpteenth time, I finally got around to implementing it:

Ben mentioned that -> could be confusing to programmers used to C++. He does have a point, but is it worth worrying about ? If so, what would be a better operator ? All I can think of is "#", ".." and ".>" ... but they all feel a bit strange.
About the author
Recent Blogs
• A Game in 2750 Days• GID23 and NPC Editor
• Fun with Lua
• How NOT to make a game
• Thinking Outside the Box
#2
09/07/2006 (5:35 pm)
After TomB posted this plan I suggested doing parent->["childName"]. It seems more obvious to me what it's doing and less like a conflict w/ normal -> semantics.
#3
09/07/2006 (5:37 pm)
Of all the suggestions so far (some of which have been incredibly bizzare, thanks Rob) I like the ->[foo] best.
#4
09/07/2006 (5:43 pm)
The problem ->[foo] is it looks too much like an array, I think.
#5
09/07/2006 (5:46 pm)
Yeh, but it would allow using expressions as the internal name. I dont think we can use ->(foo) for that due to conflicts.
#6
Firstly, setupFooGroup() now looks like this:
Heres the new syntax tests:


I dont really like the [] afterall, it feels really klunky to type. Maybe that's just due to me not changing -> yet. I ended up using class_name_expr for both of the above tests so the [] is essentially redundant.
T.
Edit: Clarification.
Edit2:
setupFooGroup() now looks like this ...
Yep, I hacked it so that if you enclose the object name in square brackets, it sets the internal name instead of the normal one. I don't think it's possible to reduce the amount of typing needed for internal names any further ;-)
T.
09/07/2006 (6:23 pm)
So, a couple more options for you. I managed to overcome extreme lazyness and finally implement a new AST ;-)Firstly, setupFooGroup() now looks like this:
function setupFooGroup()
{
new SimGroup(FooGroup)
{
new SimGroup()
{
internalName = "Bar";
new SimObject()
{
internalName = "Stuff";
};
};
new SimObject()
{
internalName = "Test";
};
};
}Heres the new syntax tests:


I dont really like the [] afterall, it feels really klunky to type. Maybe that's just due to me not changing -> yet. I ended up using class_name_expr for both of the above tests so the [] is essentially redundant.
T.
Edit: Clarification.
Edit2:
setupFooGroup() now looks like this ...
function setupFooGroup()
{
new SimGroup(FooGroup)
{
new SimGroup([Bar])
{
new SimObject([Stuff]);
};
new SimObject([Test]);
};
}Yep, I hacked it so that if you enclose the object name in square brackets, it sets the internal name instead of the normal one. I don't think it's possible to reduce the amount of typing needed for internal names any further ;-)
T.
#7
09/08/2006 (3:04 am)
The only free letters you could use for operators that i can think of are:echo(FooGroup^Test); echo(FooGroup\Test); echo(FooGroup Test); (Should be a GBP symbol there)
#8
I think that would be a good one, it's what HTML uses for bookmarks within a page, which is somewhat like internal name tags, or something.
09/08/2006 (5:26 am)
You mentioned #I think that would be a good one, it's what HTML uses for bookmarks within a page, which is somewhat like internal name tags, or something.
#9
Edit:I just remembered that "!" is a boolean "Not" operator. However, that's a one-sided operator, while this would be a two-sided operator, so it may still work.
09/08/2006 (6:39 am)
Is ! ("bang") free as an operator? That's what MS access uses, but I'm not sure if the semantics are the same. That would be short, and fairly clear.Edit:I just remembered that "!" is a boolean "Not" operator. However, that's a one-sided operator, while this would be a two-sided operator, so it may still work.
#10
Backslash, although still a bit weird feeling, might make some degree of sense. Accessing internal objects is similar to accessing paths and people are used to \ from windows. Definately can't use / due to conflicts with division, of course :)
I think the only other single char operator not already suggested that would work is :, although if you typoed a :: it might cause issues. Which brings us back to 2 char operators, of which we can probably find quite a few.
I am currently leaning towards just keeping -> ... since supporting expressions, you can now do e.g. Foo->(Name) instead of Foo->Name if you really want to which might cut down on the confusion some.
T.
09/08/2006 (8:24 am)
The problem with ^, # and ! is they feel really weird when typing them. I am not sure if ! will work for the reasons Louis mentions, it might cause conflicts. Backslash, although still a bit weird feeling, might make some degree of sense. Accessing internal objects is similar to accessing paths and people are used to \ from windows. Definately can't use / due to conflicts with division, of course :)
I think the only other single char operator not already suggested that would work is :, although if you typoed a :: it might cause issues. Which brings us back to 2 char operators, of which we can probably find quite a few.
I am currently leaning towards just keeping -> ... since supporting expressions, you can now do e.g. Foo->(Name) instead of Foo->Name if you really want to which might cut down on the confusion some.
T.
#12
09/08/2006 (10:30 am)
Haha. Some fonts make ~ look too much like - ... mores the pity :)
#13
EDIT: I noticed that you mention this one Tom although I don't think it's any less confusing than mixing up '==' with '=' or forgetting to using '$=' instead of '==" for strings. ;)
- Melv.
09/09/2006 (7:28 am)
A personal choice would be...echo( FooGroup:Test ); echo( FooGroup:Bar:Stuff );... treated as an internal name scope operator related to the object scope operator '::'.
EDIT: I noticed that you mention this one Tom although I don't think it's any less confusing than mixing up '==' with '=' or forgetting to using '$=' instead of '==" for strings. ;)
- Melv.
#14
09/09/2006 (10:41 am)
I like the way melv suggests as well.
#15
At this point I think I am leaving it as -> ... if someone finds that confusing, they can just do e.g.
Which looks weird, but works just fine due to allowing the internal name to be an expression. Of course, the brackets are only required syntactically if it actually is an expression.
T.
09/09/2006 (12:48 pm)
So, I just tried ':' as the intname operator. Unfortunately, it clashes with the query operator so there are too many shift/reduce and reduce/reduce conflicts.At this point I think I am leaving it as -> ... if someone finds that confusing, they can just do e.g.
echo(FooGroup->(Test)); echo(FooGroup->(Bar)->(Stuff));
Which looks weird, but works just fine due to allowing the internal name to be an expression. Of course, the brackets are only required syntactically if it actually is an expression.
T.
#16
No hold on .. I vote we remove the query operator ... we can always use if/then. ;)
- Melv.
09/10/2006 (1:06 am)
Fair enough Tom.No hold on .. I vote we remove the query operator ... we can always use if/then. ;)
- Melv.
#17
Aha! Clearly, the best solution is:
T.
09/10/2006 (6:36 am)
if/then ? There is no "then" in TorqueScript ;-)Aha! Clearly, the best solution is:
echo(FooGroup then Test); echo(FooGroup then Bar then Stuff);
T.
#18
And to think, I only had to complain to tom for a half year before he got bored enough to implement it
:)
-Justin
09/10/2006 (10:37 am)
This is infact, so Terribly British that it makes my pants tight. And to think, I only had to complain to tom for a half year before he got bored enough to implement it
:)
-Justin
#19
I wasn't suggesting T-Script had an "if/then"!!! By all things holy and b.a.s.i.c batman!
Edit: Site ate my post when I used a pound symbol for some reason!
- Melv.
09/10/2006 (11:02 am)
Tom,I wasn't suggesting T-Script had an "if/then"!!! By all things holy and b.a.s.i.c batman!
Edit: Site ate my post when I used a pound symbol for some reason!
- Melv.
#20
Since when did something like that prevent me from making stupid jokes ? :)
T.
09/10/2006 (12:05 pm)
Melv,Since when did something like that prevent me from making stupid jokes ? :)
T.

Associate Paul Dana