I tripped up today because I had set the wrong values type on my dictionary, so some views were implicitly getting copied upon assignment. Why does this happen? And I don’t mean why in terms of code machinery, but why was it designed this way? I feel like the dict setindex method should accept right hand sides that are strict subtypes of the key type, rather than converting - conversion should be decided explicitly by the user.
julia> d = Dict{String,Float64}()
Dict{String,Float64} with 0 entries
julia> d["foo"] = 123
123
julia> d
Dict{String,Float64} with 1 entry:
"foo" => 123.0
People love the convenience of this. Automatic conversion when values are assigned to typed locations is one of the things that makes Julia feel like a scripting language rather a fussy static language where types have to match exactly or an error gets thrown. You’ve almost certainly relied on this far more often than you realize. It is potentially problematic, however, when it ends up converting and therefore copying mutable values like arrays.