# Any reason to prefer \`::Type{T}\` over \`T::Type\`?

**URL:** <https://discourse.julialang.org/t/any-reason-to-prefer-type-t-over-t-type/103400>\
**Category:** General Usage\
**Tags:** parametric-types, style\
**Created:** [August 31, 2023, 11:18am UTC](https://discourse.julialang.org/t/any-reason-to-prefer-type-t-over-t-type/103400 "2023-08-31T11:18:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwallerb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mwallerb/32/52642_2.png) [@mwallerb](https://discourse.julialang.org/u/mwallerb)\
**Post date:** [August 31, 2023, 11:18am UTC](https://discourse.julialang.org/t/any-reason-to-prefer-type-t-over-t-type/103400/1 "2023-08-31T11:18:41Z")

</div>

Suppose you have a function which takes a type as argument, say for example convert function. If you want to constrain this type, idiomatic Julia seems to be the following:

```
convert(::Type{T}, x::Foo) where {T <: Integer}

```

However, as far as I understand, one could just as well write this as:

```
convert(T::Type{<:Integer}, x::Foo)

```

which at least to my eyes reads much cleaner. However, I’ve never seen this in the wild.

Is there a compelling reason to prefer the idiomatic (top) version?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [August 31, 2023, 11:26am UTC](https://discourse.julialang.org/t/any-reason-to-prefer-type-t-over-t-type/103400/2 "2023-08-31T11:26:30Z")

</div>

See [Performance Tips · The Julia Language](https://docs.julialang.org/en/v1/manual/performance-tips/#Be-aware-of-when-Julia-avoids-specializing)

---

<div class="post-metadata">

**Author:** ![digital\_carver](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/digital_carver/32/33818_2.png) [@digital\_carver](https://discourse.julialang.org/u/digital_carver)\
**Post date:** [September 1, 2023, 3:04am UTC](https://discourse.julialang.org/t/any-reason-to-prefer-type-t-over-t-type/103400/3 "2023-09-01T03:04:40Z")

</div>

The answer says

```
function f_type(t) # or t::Type

```

will not specialize, but

```
function g_type(t::Type{T}) where T

```

will.

```
convert(T::Type{<:Integer}, x::Foo)

```

is not exactly the same as either of those, but looks more like the second one than the first to me.

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [September 1, 2023, 5:45am UTC](https://discourse.julialang.org/t/any-reason-to-prefer-type-t-over-t-type/103400/4 "2023-09-01T05:45:35Z")

</div>

I think the main difference is just that you have access to `T` in the function body, asked about a similar case a whole ago.

> [@Parametric type signature in methods, any actual difference?](https://discourse.julialang.org/t/parametric-type-signature-in-methods-any-actual-difference/67663):
>
> Was just curious if there was actually a difference in some way between these two ways of defining a method with parametric types. function f1(x::Vector{\<:Real}) # Stuff end function f2(x::Vector{T}) where T \<: Real # Stuff end Gave a quick try where i set # Stuff to be first(x) and looked at @code\_native which seemed exactly the same, but maybe that was just so simple so it turned out the same?

---

<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:** [September 1, 2023, 5:56am UTC](https://discourse.julialang.org/t/any-reason-to-prefer-type-t-over-t-type/103400/5 "2023-09-01T05:56:24Z")

</div>

Strictly speaking, these are more equivalent argument names:

```julia
convert(S::Type{T}, x::Foo) where {T<:Integer} = ... # body can use S or T
convert(S::Type{T} where {T<:Integer}, x::Foo) = ... # body can use S

```

Only the first makes the _method_ share that parameter. One use is making multiple type annotations share that parameter, like `foo(::Type{T}, t::T) where T`. As mentioned before, It also helps force specialization with respect to that argument in the exceptional cases that Julia doesn’t do it for you, specifically when the argument has a type `Type`, `Function`, or `Vararg`.
