# Auto vs. Variant, when to use Auto?

**URL:** <https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169>\
**Category:** General\
**Created:** [May 11, 2015, 3:50am UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169 "2015-05-11T03:50:54Z")\
**Posts on this page:** 20\
**Page:** 4

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [May 12, 2015, 5:43pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/61 "2015-05-12T17:43:02Z")

</div>

[quote=186683:@Norman Palardy]An integer property prevents us from ever doing certain things with Auto  
Things we’re not discussing at this time.  
Really.[/quote]

I rather like a string like Introspection does with `t.Name`.

---

<div class="post-metadata">

**Author:** ![Joe\_Ranieri](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@Joe\_Ranieri](https://forum.xojo.com/u/Joe_Ranieri)\
**Post date:** [May 12, 2015, 5:54pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/62 "2015-05-12T17:54:46Z")

</div>

> [@186667:@Thom McGrath](#):
>
> Wouldn’t this be very slow to gather type info for each case statement?

GetTypeInfo is a constant expression, so there’s no reason it would have to be anything other than a pointer comparison.

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [May 12, 2015, 5:57pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/63 "2015-05-12T17:57:39Z")

</div>

I don’t mean the comparison would be slow. I mean the actual work of retrieving the type info. You’ll know better than I would of course, but I thought the speed issue complained about in this thread is GetTypeInfo itself.

---

<div class="post-metadata">

**Author:** ![Joe\_Ranieri](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@Joe\_Ranieri](https://forum.xojo.com/u/Joe_Ranieri)\
**Post date:** [May 12, 2015, 5:59pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/64 "2015-05-12T17:59:37Z")

</div>

> [@186692:@Thom McGrath](#):
>
> I don’t mean the comparison would be slow. I mean the actual work of retrieving the type info. You’ll know better than I would of course, but I thought the speed issue complained about in this thread is GetTypeInfo itself.

No, the gripe is that you have to call Xojo.Introspection.GetType and then compare the result’s name against text literals.

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [May 12, 2015, 6:05pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/65 "2015-05-12T18:05:39Z")

</div>

That’s only part of it. Read more of the thread. The initial complaint was that GetTypeInfo is much slower that the Variant.Type property. That is only one execution. In a select case, I imagine the effect would be even more pronounced.

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [May 12, 2015, 6:51pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/66 "2015-05-12T18:51:00Z")

</div>

There is no GetTypeInfo function in the new framework.

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [May 12, 2015, 6:54pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/67 "2015-05-12T18:54:06Z")

</div>

I think we all mean Xojo.Introspection.GetType.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cowgar](https://forum.xojo.com/user_avatar/forum.xojo.com/jeremy_cowgar/32/4590_2.png) [@Jeremy\_Cowgar](https://forum.xojo.com/u/Jeremy_Cowgar)\
**Post date:** [May 12, 2015, 7:01pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/68 "2015-05-12T19:01:56Z")

</div>

> [@186703:@Thom McGrath](#):
>
> I think we all mean Xojo.Introspection.GetType.

That won’t work because you have to pass an Instance of a class, not a class. i.e.

```auto
GetTypeInfo(String)

//vs

dim s as String = "John"
Xojo.Introspection.GetType(s)
```

Two different methods. The example Joe gave is the first, GetTypeInfo().

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cowgar](https://forum.xojo.com/user_avatar/forum.xojo.com/jeremy_cowgar/32/4590_2.png) [@Jeremy\_Cowgar](https://forum.xojo.com/u/Jeremy_Cowgar)\
**Post date:** [May 12, 2015, 7:03pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/69 "2015-05-12T19:03:28Z")

</div>

> [@186704:@Jeremy Cowgar](#):
>
> Two different methods. The example Joe gave is the first, GetTypeInfo().

Well, one is an operator, the other a method.

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [May 12, 2015, 7:05pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/70 "2015-05-12T19:05:32Z")

</div>

I think what Joe is getting at is though this can’t currently work, that is one option they are considering in the future.[quote=186646:@Joe Ranieri]I suspect what will end up happening is something like this:[/quote]  
So yes, I was wrong, Xojo.Introspection.GetType is not what was meant by GetTypeInfo. But that doesn’t mean such a thing can’t be added to the new framework in the future.

---

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [May 12, 2015, 7:09pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/71 "2015-05-12T19:09:23Z")

</div>

As joe said something like the following may occur in the future

[quote=186646:@Joe Ranieri]  
I suspect what will end up happening is something like this:

`Select Case Xojo.Introspection.GetType(var)
Case GetTypeInfo(String)
  // Do something
Case GetTypeInfo(Integer)
  // Do something
Case GetTypeInfo(Double)
  // Do something
End Select`[/quote]

What you have TODAY is NOT necessarily what you’ll have to do for the rest of time

---

<div class="post-metadata">

**Author:** ![Joe\_Ranieri](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@Joe\_Ranieri](https://forum.xojo.com/u/Joe_Ranieri)\
**Post date:** [May 12, 2015, 7:19pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/72 "2015-05-12T19:19:04Z")

</div>

> [@186201:@Jeremy Cowgar](#):
>
> You also can not use `IsA` on an `Auto` safely.

Please file a bug report on this. I think this should be legal.

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [May 12, 2015, 7:48pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/73 "2015-05-12T19:48:17Z")

</div>

Why is this new data type called when it is non-automatic as non-automatic can be… (so sorry  had to much red wine accompanying a fantastic pasta dish).

---

<div class="post-metadata">

**Author:** ![Eli\_Ott](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/5f8ce5/32.png) [@Eli\_Ott](https://forum.xojo.com/u/Eli_Ott)\
**Post date:** [May 12, 2015, 7:49pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/74 "2015-05-12T19:49:25Z")

</div>

It should say … called “Auto” …

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [May 12, 2015, 7:51pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/75 "2015-05-12T19:51:26Z")

</div>

Got a better name for it? I agree the name is weird. I really dislike it, but I haven’t been able to come up with anything other than “Any.”

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cowgar](https://forum.xojo.com/user_avatar/forum.xojo.com/jeremy_cowgar/32/4590_2.png) [@Jeremy\_Cowgar](https://forum.xojo.com/u/Jeremy_Cowgar)\
**Post date:** [May 12, 2015, 8:03pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/76 "2015-05-12T20:03:15Z")

</div>

> [@186733:@Thom McGrath](#):
>
> Got a better name for it? I agree the name is weird. I really dislike it, but I haven’t been able to come up with anything other than “Any.”

Any is actually a type in quite a few languages for this exact purpose. Describes the purpose quite well, I think. I am guessing though that we are stuck with Auto. It is a weird name when you think of it though.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Cowgar](https://forum.xojo.com/user_avatar/forum.xojo.com/jeremy_cowgar/32/4590_2.png) [@Jeremy\_Cowgar](https://forum.xojo.com/u/Jeremy_Cowgar)\
**Post date:** [May 12, 2015, 8:11pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/77 "2015-05-12T20:11:07Z")

</div>

> [@186722:@Joe Ranieri](#):
>
> Please file a bug report on this. I think this should be legal.

Done: \<[https://xojo.com/issue/39308](https://xojo.com/issue/39308)\>

---

<div class="post-metadata">

**Author:** ![Thom\_McGrath](https://forum.xojo.com/user_avatar/forum.xojo.com/thom_mcgrath/32/192_2.png) [@Thom\_McGrath](https://forum.xojo.com/u/Thom_McGrath)\
**Post date:** [May 12, 2015, 8:11pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/78 "2015-05-12T20:11:16Z")

</div>

Yeah, I don’t see the name changing.

---

<div class="post-metadata">

**Author:** ![Brock\_Nash](https://forum.xojo.com/user_avatar/forum.xojo.com/brock_nash/32/1126_2.png) [@Brock\_Nash](https://forum.xojo.com/u/Brock_Nash)\
**Post date:** [May 13, 2015, 2:18pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/79 "2015-05-13T14:18:51Z")

</div>

> [@186733:@Thom McGrath](#):
>
> Got a better name for it? I agree the name is weird. I really dislike it, but I haven’t been able to come up with anything other than “Any.”

Yeah, I do. It’s called “Object” - look at how other languages handle this. There is no need for an Auto or Variant type. They just use object and every primitive has an Object Wrapper class that auto converts when needed. I really wish Xojo had done the same thing. This would also solve the issue of not have Nullable versions of all the primitives.

For example,  
dim int1 as integer = 3  
dim int2 as Xojo.Core.Integer = 3 //Uses slightly more memory, but is more versatile (can be null)

Then methods would auto cast as needed  
doSomething1(i as integer)  
doSomething2(i as Xojo.Core.Integer)

I could pass int1 or int2 into either of those methods and the compiler would automatically cast it to an integer or Xojo.Core.Integer.  
The only concern would be if int2 was null and you passed it into doSomething1() it should throw an exception.  
But there could be a helper method like int2.IntegerValue(0) that would be use 0 if the value was null.

BENEFITS:  
No need for Auto.  
Adds nullable primitive types (which is still very highly needed)  
Libraries are more shareable and usable, especially for Javascript and JSON where you sometimes need NullableInteger types etc…

---

<div class="post-metadata">

**Author:** ![Joe\_Ranieri](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/43a26b/32.png) [@Joe\_Ranieri](https://forum.xojo.com/u/Joe_Ranieri)\
**Post date:** [May 13, 2015, 2:28pm UTC](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169/80 "2015-05-13T14:28:52Z")

</div>

[quote=186902:@Brock Nash]Yeah, I do. It’s called “Object” - look at how other languages handle this. There is no need for an Auto or Variant type. They just use object and every primitive has an Object Wrapper class that auto converts when needed. I really wish Xojo had done the same thing. This would also solve the issue of not have Nullable versions of all the primitives.

For example,  
dim int1 as integer = 3  
dim int2 as Xojo.Core.Integer = 3 //Uses slightly more memory, but is more versatile (can be null)

Then methods would auto cast as needed  
doSomething1(i as integer)  
doSomething2(i as Xojo.Core.Integer)

I could pass int1 or int2 into either of those methods and the compiler would automatically cast it to an integer or Xojo.Core.Integer.  
The only concern would be if int2 was null and you passed it into doSomething1() it should throw an exception.  
But there could be a helper method like int2.IntegerValue(0) that would be use 0 if the value was null.

BENEFITS:  
No need for Auto.  
Adds nullable primitive types (which is still very highly needed)  
Libraries are more shareable and usable, especially for Javascript and JSON where you sometimes need NullableInteger types etc…[/quote]

The overhead of making all intrinsic types be objects is huge. Like you mentioned, you also run into potential problems with unintentionally passing around Nil. It’s much better to have nullability encoded explicitly into the type system, in my opinion.

[Previous page](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169.md?page=3)

[Next page](https://forum.xojo.com/t/auto-vs-variant-when-to-use-auto/24169.md?page=5)
