# Display NTuples with more than one element as NTuples rather than Tuples?

**URL:** <https://discourse.julialang.org/t/display-ntuples-with-more-than-one-element-as-ntuples-rather-than-tuples/104143>\
**Category:** Internals & Design\
**Tags:** tuple\
**Created:** [September 22, 2023, 10:36am UTC](https://discourse.julialang.org/t/display-ntuples-with-more-than-one-element-as-ntuples-rather-than-tuples/104143 "2023-09-22T10:36:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 22, 2023, 10:36am UTC](https://discourse.julialang.org/t/display-ntuples-with-more-than-one-element-as-ntuples-rather-than-tuples/104143/1 "2023-09-22T10:36:04Z")

</div>

This example is somewhat specific to making displayed types more legible, although this might help more generally.  
Currently, we have

```julia
julia> Tuple{Int, Int, Int}
Tuple{Int64, Int64, Int64}

julia> Tuple{Int, Int, Int, Int}
NTuple{4, Int64}

```

I feel the latter form is much more readable, and would prefer this display for 2 or 3-element `NTuple`s as well. This becomes especially important if the individual elements are long:

```julia
julia> using BlockArrays, ArrayLayouts

julia> T = BlockedUnitRange{ArrayLayouts.RangeCumsum{Int64, StepRange{Int64, Int64}}};

julia> Tuple{T, T, T}
Tuple{BlockedUnitRange{RangeCumsum{Int64, StepRange{Int64, Int64}}}, BlockedUnitRange{RangeCumsum{Int64, StepRange{Int64, Int64}}}, BlockedUnitRange{RangeCumsum{Int64, StepRange{Int64, Int64}}}}

julia> Tuple{T, T, T, T}
NTuple{4, BlockedUnitRange{RangeCumsum{Int64, StepRange{Int64, Int64}}}}

```

The latter is certainly more concise and easier to parse than the former.

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 24, 2023, 6:07pm UTC](https://discourse.julialang.org/t/display-ntuples-with-more-than-one-element-as-ntuples-rather-than-tuples/104143/2 "2023-09-24T18:07:12Z")

</div>

PR created:

> <https://github.com/JuliaLang/julia/pull/51437>
>
> The motivation for this is presented in \[a discourse post\](https://discourse.jul…ialang.org/t/display-ntuples-with-more-than-one-element-as-ntuples-rather-than-tuples/104143).
> Currently,
> \`\`\`julia
> julia\> Tuple{Int, Int, Int}
> Tuple{Int64, Int64, Int64}
> 
> julia\> Tuple{Int, Int, Int, Int}
> NTuple{4, Int64}
> \`\`\`
> The latter form is much easier to read if the type parameters are long. For example, compare
> \`\`\`julia
> julia\> T = typeof(Base.IdentityUnitRange(3:4));
> 
> julia\> Tuple{T,T,T}
> Tuple{Base.IdentityUnitRange{UnitRange{Int64}}, Base.IdentityUnitRange{UnitRange{Int64}}, Base.IdentityUnitRange{UnitRange{Int64}}}
> 
> julia\> Tuple{T,T,T,T}
> NTuple{4, Base.IdentityUnitRange{UnitRange{Int64}}}
> \`\`\`
> 
> This PR changes the behavior to use the latter form for all \`NTuple\`s, so after this PR we will have
> \`\`\`julia
> julia\> Tuple{Int, Int}
> NTuple{2, Int64}
> 
> julia\> T = typeof(Base.IdentityUnitRange(3:4));
> 
> julia\> Tuple{T,T,T}
> NTuple{3, Base.IdentityUnitRange{UnitRange{Int64}}}
> \`\`\`
> This feels a bit clunky at first glance for \`Tuple{Int, Int}\` --- and might take a little getting-used-to --- but an \`NTuple\` assures homogeneity of parameters which one needs to manually assert otherwise, and secondly, the number of elements and the type parameter are easy to read without having to scan a long list of parameters manually.
> 
> The cutoff is also used for the \`Vararg\` form for tuples with homogeneous tails, which I have less of an opinion about, but perhaps the same applies there as well.

---

<div class="post-metadata">

**Author:** ![maxkapur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maxkapur/32/21208_2.png) [@maxkapur](https://discourse.julialang.org/u/maxkapur)\
**Post date:** [September 24, 2023, 6:11pm UTC](https://discourse.julialang.org/t/display-ntuples-with-more-than-one-element-as-ntuples-rather-than-tuples/104143/3 "2023-09-24T18:11:25Z")

</div>

Would this constitute a breaking change? I should hope that nobody is using `string(typeof(some_tuple)))` in Julia code but it might matter to some shell script.

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [September 25, 2023, 5:41am UTC](https://discourse.julialang.org/t/display-ntuples-with-more-than-one-element-as-ntuples-rather-than-tuples/104143/4 "2023-09-25T05:41:02Z")

</div>

There have been quite a few changes to displayed forms in minor releases, e.g. named tuples in a recent release, and the `Array{T,1}` to `Vector{T}` change sometime bank. This isn’t seen as breaking.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [September 25, 2023, 4:49pm UTC](https://discourse.julialang.org/t/display-ntuples-with-more-than-one-element-as-ntuples-rather-than-tuples/104143/5 "2023-09-25T16:49:38Z")

</div>

This is really a taste/preference thing. Personally, I like the current print-up-to-three behavior; I often find three is used as a cutoff before eliding in many contexts.

If you just have a handful of commonly-used long types like that, you could export them from your package and then printing will use those shorthands:

```julia
julia> import BlockArrays, ArrayLayouts

julia> @eval BlockArrays begin
       const StepAxis = BlockedUnitRange{ArrayLayouts.RangeCumsum{Int64, StepRange{Int64, Int64}}}
       export StepAxis
       end

julia> T = BlockArrays.BlockedUnitRange{ArrayLayouts.RangeCumsum{Int64, StepRange{Int64, Int64}}}
StepAxis (alias for BlockArrays.BlockedUnitRange{ArrayLayouts.RangeCumsum{Int64, StepRange{Int64, Int64}}})

julia> Tuple{T,T,T}
Tuple{BlockArrays.StepAxis, BlockArrays.StepAxis, BlockArrays.StepAxis}

```
