# @show displays spurious information?

**URL:** <https://discourse.julialang.org/t/show-displays-spurious-information/11524>\
**Category:** General Usage\
**Created:** [June 8, 2018, 1:01am UTC](https://discourse.julialang.org/t/show-displays-spurious-information/11524 "2018-06-08T01:01:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [June 8, 2018, 1:01am UTC](https://discourse.julialang.org/t/show-displays-spurious-information/11524/1 "2018-06-08T01:01:16Z")

</div>

Sorry if this is a silly question but I don’t recall `@show` displaying spurious information like the following illustrates. Is that really the intended behavior?

```julia
   _ _ _(_)_ | A fresh approach to technical computing
  (_) | (_) (_) | Documentation: https://docs.julialang.org
   _ _ _| |_ __ _ | Type "?help" for help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 0.6.3 (2018-05-28 20:20 UTC)
 _/ |\ __'_|_|_|\__'_| | Official http://julialang.org/ release
|__/ | x86_64-apple-darwin14.5.0

julia> A = rand(5,5);

julia> @show A
A = [0.738962 0.030631 0.0414155 0.92469 0.819403; 0.0795628 0.261736 0.467157 0.172408 0.564304; 0.752273 0.204407 0.0575049 0.778186 0.72415; 0.551209 0.121949 0.790782 0.376882 0.331133; 0.400236 0.254467 0.791898 0.713791 0.459024]
5×5 Array{Float64,2}:
 0.738962 0.030631 0.0414155 0.92469 0.819403
 0.0795628 0.261736 0.467157 0.172408 0.564304
 0.752273 0.204407 0.0575049 0.778186 0.72415 
 0.551209 0.121949 0.790782 0.376882 0.331133
 0.400236 0.254467 0.791898 0.713791 0.459024

julia> @show 2
2 = 2
2

julia> @show π
π = π = 3.1415926535897...
π = 3.1415926535897...

```

The last one looks especially silly. Only the last part of the output seems useful to me.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 8, 2018, 1:13am UTC](https://discourse.julialang.org/t/show-displays-spurious-information/11524/2 "2018-06-08T01:13:55Z")

</div>

The π example is a bit goofy, but there’s nothing really wrong going on here. `@show x` always prints `x =` and then whatever `Base.repr(x)` returns. It also returns the value of `x`, which the REPL then happily displays for you. You can see that with `macroexpand`:

```julia
julia> @macroexpand @show x
quote 
    (Base.println)("x = ", (Base.repr)(begin # show.jl, line 243:
                #2#value = x
            end))
    #2#value
end

```

`Base.repr(π)` is `"π = 3.1415926535897..."`, presumably to indicate that this is (a) indeed the pi which is approximately 3.14 and not some other pi but also (b) not a floating-point approximation but a representation of the exact number. It just looks goofy when you do `@show pi` for the same reason that `@show 2` looks odd.

`@show` is used when you want to show both a value and the name of the variable it’s bound to. If that’s not what you want, then `println()` is probably the right choice.

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [June 8, 2018, 1:32am UTC](https://discourse.julialang.org/t/show-displays-spurious-information/11524/3 "2018-06-08T01:32:24Z")

</div>

Thanks. I’ve never found `println` particularly useful as it dumps everything wholesale:

```julia
julia> println(A)
[2.19053 1.17125 0.983764 0.204726 1.48619; 1.17125 1.0 0.0 0.19505 0.14318; 0.983764 0.0 1.0 0.620039 0.817307; 0.204726 0.19505 0.620039 1.0 1.03617; 1.48619 0.14318 0.817307 1.03617 1.17563]

```

How would one get

```julia
julia> friendly_print(A)
5×5 Array{Float64,2}:
 0.738962 0.030631 0.0414155 0.92469 0.819403
 0.0795628 0.261736 0.467157 0.172408 0.564304
 0.752273 0.204407 0.0575049 0.778186 0.72415 
 0.551209 0.121949 0.790782 0.376882 0.331133
 0.400236 0.254467 0.791898 0.713791 0.459024

```

In the REPL, one can simply type `A`, but how about in a script?

---

<div class="post-metadata">

**Author:** ![dpo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpo/32/3335_2.png) [@dpo](https://discourse.julialang.org/u/dpo)\
**Post date:** [June 8, 2018, 1:36am UTC](https://discourse.julialang.org/t/show-displays-spurious-information/11524/4 "2018-06-08T01:36:46Z")

</div>

`display(A)` seems to do it. I must admit I’m totally missing the point of `@show`.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [June 8, 2018, 1:43am UTC](https://discourse.julialang.org/t/show-displays-spurious-information/11524/5 "2018-06-08T01:43:10Z")

</div>

`@show` is not particularly useful at the REPL. It’s meant to be used inside a block of code where just printing a value is less helpful than also showing what variable it’s bound to.

```julia
<code here>
@show a
<more code>
@show b

```

makes it obvious which of the printed values is `a` and which is `b`.
