# Why \`get(d, k, default)\` allows \`default\` of a type different than \`valtype(d)\`?

**URL:** https://discourse.julialang.org/t/why-get-d-k-default-allows-default-of-a-type-different-than-valtype-d/12139
**Category:** Internals & Design
**Tags:** proposal
**Created:** [July 3, 2018, 5:14pm UTC](https://discourse.julialang.org/t/why-get-d-k-default-allows-default-of-a-type-different-than-valtype-d/12139 "2018-07-03T17:14:08Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [July 3, 2018, 5:14pm UTC](https://discourse.julialang.org/t/why-get-d-k-default-allows-default-of-a-type-different-than-valtype-d/12139/1 "2018-07-03T17:14:08Z")

</div>

I don’t understand why `get(d, k, default)` allows `default` to be of a type different than `valtype(d)`. This violates type-stability, and it has been a source of may bugs for me. I have heard an argument that sometimes people return something else to signal that the key was not found. But isn’t that what `haskey` is for?

---

<div class="post-metadata">

### Author: ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)
#### Post date: [July 3, 2018, 5:28pm UTC](https://discourse.julialang.org/t/why-get-d-k-default-allows-default-of-a-type-different-than-valtype-d/12139/2 "2018-07-03T17:28:02Z")

</div>

Julia is a dynamic language, so it doesn’t generally enforce type stability. Notably, using `nothing` as a default can be useful in some cases. I agree sometimes it would be nice to have `get` call `convert(valtype(d), default)`, but that would be less flexible/general. Note that calling `haskey` first and then `get`/`getindex` requires looking up the key twice, which has a performance impact.
