Has `undef` lost its undefedness?


I had thought that current practice is to initialize arrays to undef and to test if values has been assigned with isassigned. On

julia> versioninfo()
Julia Version 0.7.0-beta.276
Commit 70bd2c2116* (2018-07-12 12:55 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3570 CPU @ 3.40GHz
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, ivybridge)

I get

julia> tt = Matrix{Int}(undef, (2,5))
2×5 Array{Int64,2}:
 0  0  0  0  0
 0  0  0  0  0

julia> similar(tt)
2×5 Array{Int64,2}:
 139787846964720                1  139787846964880  4                2
 139787846964640  139787846964800  139787846964960  3  139787817320961

julia> isassigned(tt, 1)

in contrast to what I read in the documentation for isassigned.


The #undef values in arrays are only for “pointer types” that cannot be stored in arrays inline, like mutable structs and such. Bits types have always just given you uninitialized memory in this situation.


Okay, that makes sense. I seem to recall being given deprecation warnings about e.g. Vector{Int}(20), which should be changed to Vector{Int}(undef, 20). That seems a bit hard line if the undef has no effect.


We don’t want exposing undefined memory to be a silent default. The Vector{Int}(n) constructor will be reclaimed in the future: in general, Vector(x) will construct a vector by iterating x and Vector{T}(x) will construct a Vector{T} by iterating x.


Strictly speaking, how can you tell if it has no effect (with bits types)? It is literally undefined, so it may as well be 0 or equivalent. You just can’t rely on it.