# Would a function istypestable(foo, x) make sense for beginners?

**URL:** <https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696>\
**Category:** Internals & Design\
**Created:** [February 18, 2022, 1:19pm UTC](https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696 "2022-02-18T13:19:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 18, 2022, 1:19pm UTC](https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696/1 "2022-02-18T13:19:45Z")

</div>

Given the importance for performances of type stability, I wonder if the `@code_warntype` macro, where the type stability is somehow hidden in the type of `Body:` is the easiest pick for newcomers or if instead a simpler `istypestable(foo,x)` (or `@istypestable foo(x)` ) would be easier to pick for them.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [February 18, 2022, 1:41pm UTC](https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696/2 "2022-02-18T13:41:51Z")

</div>

`@inferred` does what you want.

---

<div class="post-metadata">

**Author:** ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Post date:** [February 18, 2022, 1:54pm UTC](https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696/3 "2022-02-18T13:54:45Z")

</div>

well, yes… but not exactly… first it requires `Test` and then it either returns nothing or generates a “strange” error (from the point of view of a newcomer).  
I think `istypestable` (returning a simple true/false) would be a more direct message…

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [February 18, 2022, 1:57pm UTC](https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696/4 "2022-02-18T13:57:07Z")

</div>

I think in the “improving time to first X” long thread there was some sort of method shown to find `Core.Box` instances. So if my memory serves me correctly, that could be a good starting point for a function like this.

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 18, 2022, 2:13pm UTC](https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696/5 "2022-02-18T14:13:49Z")

</div>

Another way it might not be exact is that a method call can have a fully inferred return type but still have type instabilities and performance hits in the middle, an example is a type-unstable method patched with an annotated return type.

So there are at least 2 methods of interest, the 1st returns the inferred return type (which could be abstract), and the 2nd checks if `@code_warntype` has fully inferred types throughout. I say at least 2 because some type instabilities are fine with Union-splitting, so there may also be a version that overlooks the small Unions.

---

<div class="post-metadata">

**Author:** ![Salmon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/salmon/32/22968_2.png) [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Post date:** [March 13, 2022, 11:49am UTC](https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696/6 "2022-03-13T11:49:07Z")

</div>

On another note, it seems to me that such a function would maybe not only be good for beginners but might also be nice for unit testing of performance-critical code. Afaik there seems to be no way of doing this in Base Julia.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 13, 2022, 4:06pm UTC](https://discourse.julialang.org/t/would-a-function-istypestable-foo-x-make-sense-for-beginners/76696/7 "2022-03-13T16:06:26Z")

</div>

JET.jl kind of does this but better.
