# Design of outer constructors

**URL:** <https://discourse.julialang.org/t/design-of-outer-constructors/33937>\
**Category:** General Usage\
**Created:** [January 29, 2020, 3:08pm UTC](https://discourse.julialang.org/t/design-of-outer-constructors/33937 "2020-01-29T15:08:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 29, 2020, 3:08pm UTC](https://discourse.julialang.org/t/design-of-outer-constructors/33937/1 "2020-01-29T15:08:24Z")

</div>

in [StaticArrays](https://github.com/JuliaArrays/StaticArrays.jl/blob/3a9291df5407230ac8cce5aec025abaa068fd5d4/src/SArray.jl#L32)

```julia
@generated function (::Type{SArray{S, T, N}})(x::Tuple) where {S <: Tuple, T, N}
    return quote
        @_inline_meta
        SArray{S, T, N, $(tuple_prod(S))}(x)
    end
end

```

I see the use of generated function for outer constructors.

what is the difference (and disadvantage) using the following instead?

```julia
SArray{S, T, N}(x::Tuple) where {S<:Tuple, T, N} = 
    SArray{S, T, N, tuple_prod(S) }(x)

```

on the other hand, in [here](https://github.com/JuliaArrays/StaticArrays.jl/blob/3a9291df5407230ac8cce5aec025abaa068fd5d4/src/SDiagonal.jl#L11):

```julia
@inline (::Type{SDiagonal{N,T}})(a::Tuple) where {N,T} = Diagonal(SVector{N,T}(a))

```

why don’t we define the following?

```julia
@inline SDiagonal{N,T}(a::Tuple) where {N,T} = Diagonal(SVector{N,T}(a))

```

thanks.

---

<div class="post-metadata">

**Author:** ![tomtom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomtom/32/5106_2.png) [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Post date:** [January 30, 2020, 4:59pm UTC](https://discourse.julialang.org/t/design-of-outer-constructors/33937/2 "2020-01-30T16:59:21Z")

</div>

maybe I know the answer of the first case: using generated function could push the computation of `tuple_prod(s)` into compilation time.

what about the second case? why use

```julia
(::Type{T})(x) = ...

```

instead of

```julia
T(x) = ...

```

?

thanks.
