# Why is it \`close(::Channel)\` instead of \`close!(::Channel)\`?

**URL:** <https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261>\
**Category:** General Usage\
**Tags:** channel\
**Created:** [May 15, 2019, 10:24pm UTC](https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261 "2019-05-15T22:24:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonas-schulze](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonas-schulze/32/9228_2.png) [@jonas-schulze](https://discourse.julialang.org/u/jonas-schulze)\
**Post date:** [May 15, 2019, 10:24pm UTC](https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261/1 "2019-05-15T22:24:56Z")

</div>

Out of curiosity, why does closing a channel not have a `!` in its name?

---

<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:** [May 15, 2019, 11:24pm UTC](https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261/2 "2019-05-15T23:24:34Z")

</div>

There is no explicit data structure being mutated. Yes, I/O operations change the state of the I/O stream but that’s inherent to the way they function. It could be viewed the other way but then all I/O operations would end in `!` which seems unnecessary.

---

<div class="post-metadata">

**Author:** ![jonas-schulze](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonas-schulze/32/9228_2.png) [@jonas-schulze](https://discourse.julialang.org/u/jonas-schulze)\
**Post date:** [May 15, 2019, 11:47pm UTC](https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261/3 "2019-05-15T23:47:15Z")

</div>

True, `println!(42)` would be odd. Though it’s actually doing quite a similar thing compared to `put!(chan, 42)`, isn’t it?

While `close()` might not be changing a data structure, from a users perspective it semantically changes the channel just as much as `put!()` does. If it would not be mutating the channel (it would be a “pure” function), a `put!()` after a `close()` must not fail. I would argue that `close!()` is a better name for that function.

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [May 16, 2019, 12:49am UTC](https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261/4 "2019-05-16T00:49:35Z")

</div>

If we put `!` in the name of every function that mutated any of its arguments (or even just the first one), there’d be so many functions with `!` that it’d be useless as an indicator of mutation.

---

<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:** [May 16, 2019, 4:27am UTC](https://discourse.julialang.org/t/why-is-it-close-channel-instead-of-close-channel/24261/5 "2019-05-16T04:27:35Z")

</div>

That is the convention though and we do follow it in Base at least for mutable data structures.
