# My wishlist for the next version of Julia

**URL:** https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987
**Category:** General Usage
**Tags:** question, matlab
**Created:** [October 18, 2021, 4:28pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987 "2021-10-18T16:28:46Z")
**Posts on this page:** 20
**Page:** 3

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [October 19, 2021, 2:41pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/42 "2021-10-19T14:41:08Z")

</div>

I’m not going to be difficult to convince. I told my colleague about this (especially `arguments`). He’s been writing some simulation software for a couple of years, and a substantial part of the code base is `parseargs` and related functions. Not sure if those were tears of joy or pain.

---

<div class="post-metadata">

### Author: ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)
#### Post date: [October 19, 2021, 2:41pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/43 "2021-10-19T14:41:44Z")

</div>

As mentioned previously, if there is a function like the below in Matlab  
`[A, B, C] = f1(x, y, z, ...)`

I have the option of doing the below to tell the function do not bother to calculate B and C, so as to improve speed:  
`[A, ~, ~] = f1(x, y, z, ...)`

How can I do the same thing in Julia?

On an unrelated note, why are real values replaced with an empty value in some functions? For example, m = size(Array). m[1] will be the length of the rows and m[2] will be the length of the columns. If the Array is a one-column data, the m will be equal to (10, ) instead of (10, 1), causing an error for m[2].

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [October 19, 2021, 2:47pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/44 "2021-10-19T14:47:39Z")

</div>

Right. In Matlab the loss of legibility is probably also due to the lack of a `return stuff` statement. The function just ends…

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [October 19, 2021, 2:54pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/45 "2021-10-19T14:54:21Z")

</div>

> [@leon](#):
>
> I have the option of doing the below to tell the function do not bother to calculate B and C, so as to improve speed:  
> `[A, ~, ~] = f1(x, y, z, ...)`

I am not sure that it does that.  
I am pretty sure it stll computes `B` and `C` it just discards the value.  
That is what this [post says](https://www.mathworks.com/matlabcentral/answers/273062-does-tilda-in-a-function-output-give-any-speed-up)  
That functionality in julia is written with underscores instead: `A, _, _ = f1(x,y,z)`

Occationally the optimizer (at least i know julia’s can) will avoid computing things that are not used.  
But that is kinda regardless of if it is named `_` or some actual name with letters.  
Haskell (and weirdly TensorFlow 1.0) is the king of avoiding computing things that are not used, through lazy execution.  
The rest of us have to rely on the optimizer slicing stuff away.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [October 19, 2021, 3:01pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/46 "2021-10-19T15:01:20Z")

</div>

Julia is getting closer and closer to dead code elimination though.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [October 19, 2021, 3:06pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/47 "2021-10-19T15:06:02Z")

</div>

Yep, it works:

```julia

julia> function bar(x)
       y, _, _ = foo(x)
       return y
       end
bar (generic function with 1 method)

julia> @code_typed bar(10)
CodeInfo(
1 ─ %1 = Base.mul_int(2, x)::Int64
└── return %1
) => Int64

```

See that the `code_typed` only includes the multiplication by 2.  
Not by 3 or 4.  
as it optimized those unused computations away.  
That is in julia 1.7.  
idk when it was added.

Julia 1.0 for the same code gives

```julia
julia> @code_typed bar(10)
CodeInfo(
2 1 ─ %1 = (Base.mul_int)(2, x)::Int64 │╻╷ foo
  │ (Base.mul_int)(3, x)::Int64 ││┃ *
  │ (Base.mul_int)(4, x)::Int64 │││
3 └── return %1 │  
) => Int64

```

Though the LLVM optimizer catches that anyway

```julia
julia> @code_llvm bar(10)

; Function bar
; Location: REPL[3]:2
define i64 @julia_bar_35231(i64) {
top:
; Function foo; {
; Location: REPL[2]:1
; Function *; {
; Location: int.jl:54
  %1 = shl i64 %0, 1
;}}
; Location: REPL[3]:3
  ret i64 %1
}

```

---

<div class="post-metadata">

### Author: ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)
#### Post date: [October 19, 2021, 3:12pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/48 "2021-10-19T15:12:46Z")

</div>

> [@leon](#):
>
> On an unrelated note, why are real values replaced with an empty value in some functions? For example, m = size(Array). m[1] will be the length of the rows and m[2] will be the length of the columns. If the Array is a one-column data, the m will be equal to (10, ) instead of (10, 1), causing an error for m[2].

`size(A)` will return a `Tuple` that has as many elements as `A` has dimensions. Examples:

```julia
julia> A = ones(3) # One-dimensional, one-column data
3-element Vector{Float64}:
 1.0
 1.0
 1.0

julia> size(A)
(3,)

julia> A = ones(3, 1) # Two-dimensional, one-column data
3×1 Matrix{Float64}:
 1.0
 1.0
 1.0

julia> size(A)
(3, 1)

julia> A = ones(3, 1, 1) # Three-dimensional, one-column data
3×1×1 Array{Float64, 3}:
[:, :, 1] =
 1.0
 1.0
 1.0

julia> size(A)
(3, 1, 1)

```

(Note that `(10,)` is the syntax for a `Tuple` that has just one element. The comma `,` is needed to disambiguate from `(10)`, in which the parentheses are used for grouping operations. I.e., `(1 + 1) == 2 != (2,)`, whereas `(1 + 1,) == (2,) != 2`.)

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [October 19, 2021, 3:22pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/49 "2021-10-19T15:22:06Z")

</div>

> [@oxinabox](#):
>
> I am not sure that it does that.  
> I am pretty sure it stll computes `B` and `C` it just discards the value.

No in Matlab you can really skip the unnecessary computation. This is idiomatic in Matlab:

```octave
function [a, b] = myf(x, y)
    a = x+y;

    % Calculate b only if requested
    if nargout == 2
        b = x*y;
    end
end

```

Then calling `v = myf(2, 3)` will skip the computation of `b`, while calling `[v, w] = myf(2, 3)` will compute everything.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [October 19, 2021, 3:24pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/50 "2021-10-19T15:24:06Z")

</div>

> [@sijo](#):
>
> No in Matlab you can really skip the unnecessary computation.

that’s not what the tilde does though. No?

That is a different feature

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [October 19, 2021, 3:25pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/51 "2021-10-19T15:25:42Z")

</div>

Ah indeed! with the tilde it will compute both. But I think that was just a typo in @leon’s message, he probably meant to write

> I have the option of doing the below to tell the function do not bother to calculate B and C, so as to improve speed:  
> `A = f1(x, y, z, ...)`

---

<div class="post-metadata">

### Author: ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)
#### Post date: [October 19, 2021, 3:26pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/52 "2021-10-19T15:26:30Z")

</div>

I was going to check this, but defining functions in Matlab is really painful. I miss Julia when I’m at work.

---

<div class="post-metadata">

### Author: ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)
#### Post date: [October 19, 2021, 3:29pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/53 "2021-10-19T15:29:51Z")

</div>

> [@gustaphe](#):
>
> I was going to check this, but defining functions in Matlab is really painful.

Same here… “ugh I have to create a file somewhere”

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [October 19, 2021, 3:33pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/54 "2021-10-19T15:33:03Z")

</div>

Well you _can_ do something like this without writing a file:

```nohighlight
>> f1 = @() deal(nargout);
>> a = f1()               
a =
     1
>> [a, ~] = f1()          
a =
     2

```

which shows that with `[a, ~]` Matlab sets `nargout=2` so it computes everything.

I’m not going to argue it’s anything as nice as a function definition in Julia 🙂

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [October 19, 2021, 4:07pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/55 "2021-10-19T16:07:34Z")

</div>

> [@sijo](#):
>
> `function [a, b] = myf(x, y)`

I guess that has to be independently documented for every function that may or may not return multiple values, right?

In that case it does not seem a great advantage relative to having two very similar names, or a `kwarg`.

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [October 19, 2021, 4:33pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/56 "2021-10-19T16:33:10Z")

</div>

> [@lmiq](#):
>
> I guess that has to be independently documented for every function that may or may not return multiple values, right?

Not really, when you call a function you can always store less results than offered by the function. Documentation is only needed if the behavior of the function changes depending on the number of outputs, or if you want to make it explicit that computations can be avoided. If not documented, it’s like in Julia: maybe the unneeded computation is skipped by the optimizer, maybe not 🙂

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [October 19, 2021, 4:35pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/57 "2021-10-19T16:35:26Z")

</div>

In Matlab there are no vectors, only single-column matrices. There are arrays with higher numbers of dimensions, however, so it treats two as a special number of dimensions. I get how they ended up there: early versions _only_ had matrices, which gets you shockingly far, only later did they add higher dimensional arrays. However, that’s unsatisfying (why is two special?) and causes problems. Think of all the cases where Matlab does something special and different when a matrix happens to only have one column or row and something entirely different when the matrix has more than one column or row. This makes it very hard to write reliable code because it’s very common for everything to work fine until encounter data that happens to only have one column, and then 💥 – or worse still, you silently get garbage results. Example: if you do `sort(A)` in Matlab, it sorts each column of `A`; unless `A` happens to have a single row, in which case it sorts the row. There are many similar examples. There are also no scalars, only 1x1 matrices. This can cause many problems too: since scalars are often treated specially, there’s a lot of Matlab code that breaks if you have a matrix that happens to have size 1x1.

Julia, on the other hand, distinguishes all possible dimensions of arrays, including vectors and zero-dimensional arrays. When you do `size(A)` the number of dimension values you get back is the number of dimensions of the array. What you’re asking for is that `size(v)` give at least two dimensions back even when `v` is a vector with only one dimension. Which it could do, but again, why is two special? Why not always return three dimensions? Why not four? Maybe it should always return an infinite tuple object where all the trailing values are 1? (We could actually do that.) But instead, we return a finite tuple where the number of elements is the dimension of the array. When you’re doing `m = size(v); m[2]` and it errors, you could instead do `size(v, 2)`, which will give you 1 even if `v` is a vector—you can ask for any dimension and if it’s more than the number of dimensions of the argument array, you’ll get 1 as the answer. Note that some people find this behavior disconcerting, but it does allow writing code that treats vectors like matrices or even higher dimensional arrays.

---

<div class="post-metadata">

### Author: ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)
#### Post date: [October 19, 2021, 4:50pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/58 "2021-10-19T16:50:15Z")

</div>

> [@StefanKarpinski](#):
>
> Maybe it should always return an infinite tuple object where all the trailing values are 1? (We could actually do that.)

I love the fact that we could do that. DON’T DO THAT. But I love that it’s possible.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [October 19, 2021, 4:51pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/59 "2021-10-19T16:51:09Z")

</div>

Yeah, it would be weird… but it’s a simple wrapper type around a normal tuple.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [October 19, 2021, 4:56pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/60 "2021-10-19T16:56:08Z")

</div>

> [@sijo](#):
>
> No in Matlab you can really skip the unnecessary computation.

But there’s nothing automatic about this, inside the function there must be an explicit check with `nargout`, and then it must deliberately skip computations. If this isn’t implemented, all outputs are computed no matter how you call the function.

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [October 19, 2021, 5:26pm UTC](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987/61 "2021-10-19T17:26:34Z")

</div>

> [@sijo](#):
>
> Documentation is only needed if the behavior of the function changes depending on the number of outputs, or if you want to make it explicit that computations can be avoided.

Yes, of course, that is what I meant.

[Previous page](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987.md?page=2)

[Next page](https://discourse.julialang.org/t/my-wishlist-for-the-next-version-of-julia/69987.md?page=4)
