# Optional variable declarations

**URL:** <https://discourse.julialang.org/t/optional-variable-declarations/39951>\
**Category:** Internals & Design\
**Created:** [May 22, 2020, 10:27am UTC](https://discourse.julialang.org/t/optional-variable-declarations/39951 "2020-05-22T10:27:35Z")\
**Posts on this page:** 2\
**Page:** 3

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 22, 2020, 6:22pm UTC](https://discourse.julialang.org/t/optional-variable-declarations/39951/41 "2020-05-22T18:22:03Z")

</div>

I would code the initial example repeated below

```julia
var x::Vector
var y::(Vector,Matrix)

x=eig(A) # Computes only eigenvalues
y=eig(A) # Computes both eigenvalues and eigenvectors

```

as this:

```julia
function eig!(A, x :: Vector)
    ...
end
function eig!(A, x :: Vector, z :: Matrix)
    ...
end
x = Vector(undef, size1)
z = Matrix(undef, size1, size2)

eig!(A, x) # Computes only eigenvalues
eig!(A, x, z) # Computes both eigenvalues and eigenvectors

```

Not sure why those output types would be necessary unless it is for returning immutable structs, and in such case you can either dispatch on `RefValue` wrappers or just change the function name as it was said.

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [May 22, 2020, 6:23pm UTC](https://discourse.julialang.org/t/optional-variable-declarations/39951/42 "2020-05-22T18:23:20Z")

</div>

Argh. Now that song is in my head.

[Previous page](https://discourse.julialang.org/t/optional-variable-declarations/39951.md?page=2)
