# Some doubts about types

**URL:** <https://discourse.julialang.org/t/some-doubts-about-types/27635>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 16, 2019, 11:05pm UTC](https://discourse.julialang.org/t/some-doubts-about-types/27635 "2019-08-16T23:05:41Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 17, 2019, 1:18pm UTC](https://discourse.julialang.org/t/some-doubts-about-types/27635/5 "2019-08-17T13:18:32Z")

</div>

> [@baptiste](#):
>
> I’m inferring that Vector is an alias for 1D array, and probably Matrix an alias for 2D arrays. This leaves me with the AbstractArray concept – probably overly general for a regular kind of array?

`Array` is the built-in multidimensional array type, and in particular it is a family of types `Array{T,N}`: `N`-dimensional arrays of element type `T`. `Vector{T}` is an alias for `Array{T,1}` and `Matrix{T}` is an alias for `Array{T,2}`.

`Array` is a subtype of the abstract `AbstractArray` type — by accepting `AbstractArray` rather than `Array`, you allow your code to be used with other array types. An example in Base is a range like `1:100`, which is acts like a 1d array but its elements are computed as needed. Other examples in external packages include StaticArrays and GPUArrays.

In general, the more people you expect to re-use your code, the more generic you should try to be, so that they can combine your code arbitrarily with different packages. But as long as it is mostly you using your code, you can always go back and add more type parameters to make your code more generic. As you get more experience working with Julia, you should learn to instinctively write more generic code by default.

> [@baptiste](#):
>
> And then to initialise or define types of their entries I’m not sure if I should go for Complex{Float64}, or Complex{AbstractFloat}, or Complex{Real}.

You almost always want to parameterize by concrete types. For an explanation of why this is a critical distinction, see:

> [@Problem with Complex{Rationals}](https://discourse.julialang.org/t/problem-with-complex-rationals/9474/7):
>
> You should also understand that this distinction is absolutely critical for performance. It’s not just an arbitrary pedantic choice. Think about how instances of the types are actually stored and processed on the computer. A Complex{Rational{Int}} for a+bi can be (and is) stored as four consecutive Int (64-bit integer) values: (anum,aden,bnum,bden). For operations on such quantities, since the compiler knows everything’s type and how it is stored, it can load the numerators and denominators …

---

_[View the full topic](https://discourse.julialang.org/t/some-doubts-about-types/27635)._
