# Feature Request : Removing Unnecessary Parenthesis

**URL:** <https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607>\
**Category:** Language Design\
**Created:** [April 17, 2016, 7:06am UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607 "2016-04-17T07:06:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://avatars.discourse-cdn.com/v4/letter/g/8dc957/32.png) [@guest](https://discuss.kotlinlang.org/u/guest)\
**Post date:** [April 17, 2016, 7:06am UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/1 "2016-04-17T07:06:27Z")

</div>

Hey, What about removing unnecessary parenthesis in conditions?

Which is more readable?:

if (x == 5) {  
println!(“x is five!”)  
} else {  
println!(“x is not five”)  
}

vs

if x == 5 {  
println!(“x is five!”)  
} else {  
println!(“x is not five”)  
}

Go started using this kind of syntax first and many modern programming languages like Rust, Swift adopted it. What about avoiding parenthesis for conditions and loops in Kotlin? Don’t we have a good IDE that can clearly show conditions and loops without these unnecessary parenthesis?

---

<div class="post-metadata">

**Author:** ![Markus\_M](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Markus\_M](https://discuss.kotlinlang.org/u/Markus_M)\
**Post date:** [April 17, 2016, 2:56pm UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/2 "2016-04-17T14:56:42Z")

</div>

`	if this is SimpleCondition || hasNoBranches() println("Parenthesis aren't critical") else if this is ComplexCondition || hasMultipleBranches() println("Parenthesis are very helpful") `

---

<div class="post-metadata">

**Author:** ![eddie](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/eddie/32/4031_2.png) [@eddie](https://discuss.kotlinlang.org/u/eddie)\
**Post date:** [April 17, 2016, 4:35pm UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/3 "2016-04-17T16:35:58Z")

</div>

The OP suggested removing unnecessary parentheses, and you additionally removed curly brackets as well for some reason. I’m also not sure how often you should be writing nested, single-line if-else expressions like that.

---

<div class="post-metadata">

**Author:** ![Markus\_M](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Markus\_M](https://discuss.kotlinlang.org/u/Markus_M)\
**Post date:** [April 17, 2016, 6:07pm UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/4 "2016-04-17T18:07:25Z")

</div>

“Necessity” is a subjective notion. That is Jess can decide that all parens aren’t necessary because can read any conditional expression anyway. But will such code be readable for James?

But we can go beyond. Kotlin already has following control structure:  
`when { x == 5 -> println("x is five!") else -> println("x is not five") }`  
Why not just:  
`x == 5 -> println("x is five!") else -> println("x is not five") `  
Considering `->` as some kind of postfix `if`

---

<div class="post-metadata">

**Author:** ![dnene](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/dnene/32/1853_2.png) [@dnene](https://discuss.kotlinlang.org/u/dnene)\
**Post date:** [April 18, 2016, 3:46am UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/5 "2016-04-18T03:46:59Z")

</div>

Consider the following

if a \>= b a = b else b = a

I often feel frustrated at having to type in the parenthesis and have wished many times they weren’t there. But when I think of code like above, it makes me reconsider.

As to another response suggesting that the parenthesis should be optional only conditionally, I think that makes it even harder because the writer / reader have to think of that condition every time they write an if.

Not suggesting one can’t do away with the parenthesis. But might need something to specify where the if condition ends and the block begins.

---

<div class="post-metadata">

**Author:** ![yole](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/yole/32/1425_2.png) [@yole](https://discuss.kotlinlang.org/u/yole)\
**Post date:** [April 18, 2016, 8:05am UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/6 "2016-04-18T08:05:27Z")

</div>

All of the languages you’ve listed require you to use curly braces in if statements. In Kotlin, curly braces are optional because requiring them would make single-line `if` expressions (Kotlin’s replacement for the ternary operator) too ugly. And making both curly braces and parentheses optional will inevitably lead to ambiguities. Therefore - no, in Kotlin those parentheses are not unnecessary and cannot be removed.

---

<div class="post-metadata">

**Author:** ![mikehearn](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mikehearn/32/1424_2.png) [@mikehearn](https://discuss.kotlinlang.org/u/mikehearn)\
**Post date:** [April 18, 2016, 12:02pm UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/7 "2016-04-18T12:02:14Z")

</div>

I prefer it Kotlin’s way. Adding the parens and if statement can be easily done using the IDE to turn an expression into an if expression.

---

<div class="post-metadata">

**Author:** ![sksamuel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sksamuel/32/1904_2.png) [@sksamuel](https://discuss.kotlinlang.org/u/sksamuel)\
**Post date:** [April 19, 2016, 2:58pm UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/8 "2016-04-19T14:58:20Z")

</div>

Scala allows similar in pattern guards, eg, case x if x == 2 =\> and I find that its much nicer to read over case x if (x ==2) =\>. It would be nice to do something similar in very simple if statements, it doesn’t have to work for complicated if statements.

---

<div class="post-metadata">

**Author:** ![jacobz\_20](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jacobz_20/32/1468_2.png) [@jacobz\_20](https://discuss.kotlinlang.org/u/jacobz_20)\
**Post date:** [April 23, 2016, 8:04pm UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/9 "2016-04-23T20:04:45Z")

</div>

Personally, I’d like it to go the Python way but it’s too late for THAT drastic of a syntax change 🙂  
I’m fine with parens in a language like Kotlin. It fits the style.

---

<div class="post-metadata">

**Author:** ![jacobz\_20](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jacobz_20/32/1468_2.png) [@jacobz\_20](https://discuss.kotlinlang.org/u/jacobz_20)\
**Post date:** [April 23, 2016, 8:05pm UTC](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607/10 "2016-04-23T20:05:52Z")

</div>

Go is most certainly NOT the first language to not use parens around an if conditional.
