# Is it bad style to write \`a = foo()\` instead of \`a, \_ = foo()\`?

**URL:** <https://discourse.julialang.org/t/is-it-bad-style-to-write-a-foo-instead-of-a-foo/61340>\
**Category:** New to Julia\
**Tags:** style\
**Created:** [May 18, 2021, 5:52am UTC](https://discourse.julialang.org/t/is-it-bad-style-to-write-a-foo-instead-of-a-foo/61340 "2021-05-18T05:52:08Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [May 18, 2021, 5:52am UTC](https://discourse.julialang.org/t/is-it-bad-style-to-write-a-foo-instead-of-a-foo/61340/1 "2021-05-18T05:52:08Z")

</div>

Suppose I have a function that returns two values, but I am usually only interested in the first one.

```julia
function foo()
    nit = 0
    res = 1.
    
    while res > 0.1 && nit < 500
        nit += 1
        res /= 1 + res
    end
    return res, nit
end

```

The typical way to signal to someone reading my code that I am not going to use the `nit` value would be to write

```julia
R, _ = foo()

```

However, I figured out that in Julia I can simply write

```julia
R = foo()

```

to the same effect.

Is this poor style?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [May 18, 2021, 5:59am UTC](https://discourse.julialang.org/t/is-it-bad-style-to-write-a-foo-instead-of-a-foo/61340/2 "2021-05-18T05:59:46Z")

</div>

> [@maxkapur](#):
>
> to the same effect.

```julia
julia> function foo()
           return 1,3
       end
foo (generic function with 1 method)

julia> R = foo();

julia> length(R)
2

julia> R
(1, 3)

```

not the same?

---

<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:** [May 18, 2021, 6:16am UTC](https://discourse.julialang.org/t/is-it-bad-style-to-write-a-foo-instead-of-a-foo/61340/3 "2021-05-18T06:16:06Z")

</div>

> [@maxkapur](#):
>
> ```julia
> function foo()
> nit = 0
> res = 1.
>     
> while res > 0.1 && nit < 500
> nit += 1
> res /= 1 + res
> end
> return res, nit
> end
> 
> ```

Indeed it is not. Turns out I had renamed my function along the way and `R = foo()` worked by referencing the old name.

---

<div class="post-metadata">

**Author:** ![jzr](https://avatars.discourse-cdn.com/v4/letter/j/eb9ed0/32.png) [@jzr](https://discourse.julialang.org/u/jzr)\
**Post date:** [May 18, 2021, 6:32am UTC](https://discourse.julialang.org/t/is-it-bad-style-to-write-a-foo-instead-of-a-foo/61340/4 "2021-05-18T06:32:42Z")

</div>

A similar issue is whether this is bad style:

```julia
julia> x, = 1,2
(1, 2)

julia> x
1

```

For me the answer is yes, but really it’s bad that Julia allows that at all.

---

<div class="post-metadata">

**Author:** ![goretkin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goretkin/32/167_2.png) [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Post date:** [May 18, 2021, 8:42pm UTC](https://discourse.julialang.org/t/is-it-bad-style-to-write-a-foo-instead-of-a-foo/61340/5 "2021-05-18T20:42:28Z")

</div>

> [@jzr](#):
>
> it’s bad that Julia allows that at all.

I agree. Here’s an issue tracking it: [Stricter tuple destructuring. Error on `(a, b) = (1, 2, 3)` · Issue #37132 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/37132)
