# If needs else branch in expression of type Unit

**URL:** <https://discuss.kotlinlang.org/t/if-needs-else-branch-in-expression-of-type-unit/7970>\
**Category:** Language Design\
**Created:** [May 31, 2018, 1:21pm UTC](https://discuss.kotlinlang.org/t/if-needs-else-branch-in-expression-of-type-unit/7970 "2018-05-31T13:21:25Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![roschlau](https://avatars.discourse-cdn.com/v4/letter/r/cdc98d/32.png) [@roschlau](https://discuss.kotlinlang.org/u/roschlau)\
**Post date:** [June 6, 2018, 7:54am UTC](https://discuss.kotlinlang.org/t/if-needs-else-branch-in-expression-of-type-unit/7970/15 "2018-06-06T07:54:16Z")

</div>

I don’t think special treatment of `if` in such a special edge case is justified. Kotlin tries to push you toward immutability and reducing side effects, and a `when` expression with a `Unit` return type just screams “SIDE EFFECT”. Sure, a lot of the time you can’t avoid those cases, but I’m not sure the language should actively encourage them. I think having a little more verbosity in a case like this is quite acceptable, because it makes inadvertently creating side effects harder.

---

_[View the full topic](https://discuss.kotlinlang.org/t/if-needs-else-branch-in-expression-of-type-unit/7970)._
