# In vs haskey order of parameters

**URL:** <https://discourse.julialang.org/t/in-vs-haskey-order-of-parameters/1128>\
**Category:** Internals & Design\
**Created:** [December 24, 2016, 4:07am UTC](https://discourse.julialang.org/t/in-vs-haskey-order-of-parameters/1128 "2016-12-24T04:07:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomasPuverle](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@TomasPuverle](https://discourse.julialang.org/u/TomasPuverle)\
**Post date:** [December 24, 2016, 4:07am UTC](https://discourse.julialang.org/t/in-vs-haskey-order-of-parameters/1128/1 "2016-12-24T04:07:03Z")

</div>

Hello,

I was wondering if there was any reason why the signatures of some of the collection methods are “inconsistent”. For example,

`in(` **value** `, collection)`, but `haskey(dict, ` **key** `)`, but perhaps again `push!(collection, ` **value** `)`.

Especially, `in` appears a bit “backwards”, even just reading the code.

Thanks,

Tom

---

<div class="post-metadata">

**Author:** ![swt30](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swt30/32/4667_2.png) [@swt30](https://discourse.julialang.org/u/swt30)\
**Post date:** [December 24, 2016, 11:17am UTC](https://discourse.julialang.org/t/in-vs-haskey-order-of-parameters/1128/2 "2016-12-24T11:17:19Z")

</div>

I’d say that the first two functions have sort-of-opposite meanings. You can see this more clearly if you write them in infix form. `in` has an infix form: `value in collection`. `haskey` doesn’t but if it did: `dict haskey key`, which makes sense. And for functions with `!` the convention seems to be that they modify their first argument, hence why `collection` comes first.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [December 24, 2016, 2:50pm UTC](https://discourse.julialang.org/t/in-vs-haskey-order-of-parameters/1128/3 "2016-12-24T14:50:26Z")

</div>

In addition to what you’d said, another reason is that `push!` also allows for multiple values to be pushed to the collection, for example: `push!(arr, 1, 2, 3)`

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 24, 2016, 7:09pm UTC](https://discourse.julialang.org/t/in-vs-haskey-order-of-parameters/1128/4 "2016-12-24T19:09:07Z")

</div>

For that matter, we could entirely remove `haskey(dict, key)` in favor of `key in keys(dict)`.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [December 24, 2016, 9:15pm UTC](https://discourse.julialang.org/t/in-vs-haskey-order-of-parameters/1128/5 "2016-12-24T21:15:45Z")

</div>

At least on master, that generates slightly less efficient code than `haskey` (at least for `Dict`, I’m not sure about if it would be even worse for other types of collections), and it might require () around it depending on what sort of expression it is in.

---

<div class="post-metadata">

**Author:** ![TomasPuverle](https://avatars.discourse-cdn.com/v4/letter/t/ecccb3/32.png) [@TomasPuverle](https://discourse.julialang.org/u/TomasPuverle)\
**Post date:** [December 26, 2016, 8:10pm UTC](https://discourse.julialang.org/t/in-vs-haskey-order-of-parameters/1128/6 "2016-12-26T20:10:21Z")

</div>

Thank you all for the answers.
