# Remove if branches, or make optional

**URL:** <https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233>\
**Category:** Language Design\
**Created:** [August 17, 2017, 7:44am UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233 "2017-08-17T07:44:43Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![kojiba](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/kojiba/32/3596_2.png) [@kojiba](https://discuss.kotlinlang.org/u/kojiba)\
**Post date:** [August 17, 2017, 7:44am UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/1 "2017-08-17T07:44:43Z")

</div>

How about, remove branches “()” in if syntax, or make it optional to use

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [August 17, 2017, 7:56am UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/2 "2017-08-17T07:56:57Z")

</div>

1. You probably mean _braces_, not _branches_
2. A terrible idea. Kotlin is made to be familiar for Java / C / any “curly braces” users. One does not want to break it. Also in current kotlin paradigm, `if` looks like a function with closure argument and it is very good, since it works like function with closure argument.
3. It obviously would tremendously complicate code parsing.

---

<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:** [August 17, 2017, 8:51am UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/3 "2017-08-17T08:51:40Z")

</div>

The parentheses in an `if` statement can be optional if the curly braces or another type of block delimiter are required, as in Go or Pascal. In Kotlin, the block delimiter is not required, so we need to have another type of delimiter between the condition and the expression - and the parentheses are that delimiter.

---

<div class="post-metadata">

**Author:** ![kojiba](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/kojiba/32/3596_2.png) [@kojiba](https://discuss.kotlinlang.org/u/kojiba)\
**Post date:** [August 17, 2017, 7:59pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/4 "2017-08-17T19:59:26Z")

</div>

I have meant round brackets, sry for misunderstanding

If Kotlin is position itself like a new type lang for development it must take all of syntax sugaring from Swift.  
Its not a C/Java, its a new language for comfortable development, not for storing old rudiments.

What I mean:

```
if someCondition && condition2 {
    someStatementOrCall()
    ...
}

```

optional: (its better to always have curly braces, if hard to parse this)

```
if someCondition
    sigleLineStatement()

```

Also why argument labels using ‘=’ instead of ‘:’ ?) C++ rudiment, too?

---

<div class="post-metadata">

**Author:** ![kojiba](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/kojiba/32/3596_2.png) [@kojiba](https://discuss.kotlinlang.org/u/kojiba)\
**Post date:** [August 17, 2017, 8:13pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/5 "2017-08-17T20:13:40Z")

</div>

Can U pls demonstrate valid if-else statement without block delimiters, not sure where it is not required for multiline statements

---

<div class="post-metadata">

**Author:** ![jstuyts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstuyts/32/2141_2.png) [@jstuyts](https://discuss.kotlinlang.org/u/jstuyts)\
**Post date:** [August 17, 2017, 8:27pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/6 "2017-08-17T20:27:09Z")

</div>

> [@kojiba](#):
>
> […] it must take all of syntax sugaring from Swift.

Which language design law says so? Kotlin has had and has different goals than Swing. Different goals result in different syntax.

You cannot expect to be productive in a new language immediately. You must take time to learn each language. There can be a lot of concepts that are the same as those you know from languages you already know, but the syntax and semantics in each language are very likely to differ. Sometimes a bit, and sometimes a lot.

Kotlin has a lot of very nice features, and very exciting things (multi-platform and coroutines amongst others) are in the pipeline. It is up to you to decide if these features are worth the effort of getting to know Kotlin.

> [@kojiba](#):
>
> Can U pls demonstrate valid if-else statement without block delimiters, not sure where it is not required for multiline statements

For multi-line blocks the braces are always required, but it is undesirable to require them for single-statement/single-expression blocks. Compare these two statements:

```
val x = if (someCondition) { 3 } else { 4 }
val x = if (someCondition) 3 else 4

```

---

<div class="post-metadata">

**Author:** ![kojiba](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/kojiba/32/3596_2.png) [@kojiba](https://discuss.kotlinlang.org/u/kojiba)\
**Post date:** [August 17, 2017, 8:43pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/7 "2017-08-17T20:43:26Z")

</div>

> [@jstuyts](#):
>
> For multi-line blocks the braces are always required,

Ok, than, why we need a round brackets if we have block delimeter?

> [@jstuyts](#):
>
> Which language design law says so?

The law about more sugar = more users. Now we watching a big migrate from Java to Kotlin only cause of syntax sugar. Yes, I have coded in old vanilla C too, but if U make a new PL, U need to be guided by another new PLs, to run a good market competition. Btw, PL main aim must be is to keep balance in readability/brevity, i.e. cut off unneeded things, even if it will have a harder processing.

---

<div class="post-metadata">

**Author:** ![jstuyts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstuyts/32/2141_2.png) [@jstuyts](https://discuss.kotlinlang.org/u/jstuyts)\
**Post date:** [August 17, 2017, 8:59pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/8 "2017-08-17T20:59:28Z")

</div>

> [@kojiba](#):
>
> Ok, than, why we need a round brackets if we have block delimeter?

Because you can leave of the braces if you only have 1 statement/expression, and if you don’t use parentheses in this case, the parser will become a lot more complex and slower. Try building a toy parser yourself that supports your proposed syntax.

> [@kojiba](#):
>
> […] , but if U make a new PL, U need to be guided by another new PLs, to run a good market competition. Btw, PL main aim must be is to keep balance in readability/brevity, i.e. cut off unneeded things, even if it will have a harder processing.

You keep saying this without anything to back this up. Why do all new programming languages have to look alike? Given language design history, it is very unlikely there is one true design that is clearly better than others. And how can you objectively measure readability? I think LISP-like code is horrible, but other people find it readable.

Kotlin already has reduced the number of unneeded things. In my experience the amount of needed code is about 50% of that of Java. And building reasonably simple Kotlin projects already takes too much time in my opinion, so a syntax that makes compilation take even longer is undesirable for me.

---

<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:** [August 18, 2017, 5:24am UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/9 "2017-08-18T05:24:23Z")

</div>

That subj was being already discussed here [https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607)

---

<div class="post-metadata">

**Author:** ![kojiba](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/kojiba/32/3596_2.png) [@kojiba](https://discuss.kotlinlang.org/u/kojiba)\
**Post date:** [August 18, 2017, 12:35pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/10 "2017-08-18T12:35:30Z")

</div>

> [@Markus\_M](#):
>
> That subj was being already discussed here [Feature Request : Removing Unnecessary Parenthesis](https://discuss.kotlinlang.org/t/feature-request-removing-unnecessary-parenthesis/1607)

yeah, its better to save ternary operator istead of keeping round brackets  
will be cool to make a voting for this feature, but I think its unreal

very imho: jetbrains must fire them senior language designer (hello from literal container initializers, and other shit design))

gl hf

---

<div class="post-metadata">

**Author:** ![jstuyts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/jstuyts/32/2141_2.png) [@jstuyts](https://discuss.kotlinlang.org/u/jstuyts)\
**Post date:** [August 18, 2017, 2:13pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/11 "2017-08-18T14:13:14Z")

</div>

> [@kojiba](#):
>
> very imho: jetbrains must fire them senior language designer (hello from literal container initializers, and other shit design))

If you cannot stand Kotlin, why not switch to a language you do love? There are many to choose from. Why do you insist on using Kotlin, but then demand that it must be changed to a completely different language?

---

<div class="post-metadata">

**Author:** ![rivuchk](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/rivuchk/32/3616_2.png) [@rivuchk](https://discuss.kotlinlang.org/u/rivuchk)\
**Post date:** [August 18, 2017, 3:01pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/12 "2017-08-18T15:01:35Z")

</div>

= instead of : in argument, as in Kotlin, : is used to declare data types, so having : again for arguments will confuse developers.

---

<div class="post-metadata">

**Author:** ![Tim\_van\_der\_Leeuw.1](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/tim_van_der_leeuw.1/32/9155_2.png) [@Tim\_van\_der\_Leeuw.1](https://discuss.kotlinlang.org/u/Tim_van_der_Leeuw.1)\
**Post date:** [August 18, 2017, 3:27pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/13 "2017-08-18T15:27:35Z")

</div>

My coworker just commented that the number of users who rejected Kotlin because it requires braces around the condition of an if, is probably exactly 1.

---

<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:** [August 18, 2017, 6:00pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/14 "2017-08-18T18:00:36Z")

</div>

Please keep the discussion constructive. If you have specific feedback on specific design decisions, you’re welcome to share it, but if you find Kotlin’s design to be unsatisfactory in general, please use a different language. There’s plenty to choose from.

---

<div class="post-metadata">

**Author:** ![nyxcode](https://avatars.discourse-cdn.com/v4/letter/n/3da27b/32.png) [@nyxcode](https://discuss.kotlinlang.org/u/nyxcode)\
**Post date:** [September 10, 2017, 3:10pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/15 "2017-09-10T15:10:55Z")

</div>

`val x = if boolean somevalue else someothervalue` looks horrible and is hard to read.

---

<div class="post-metadata">

**Author:** ![kojiba](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/kojiba/32/3596_2.png) [@kojiba](https://discuss.kotlinlang.org/u/kojiba)\
**Post date:** [September 10, 2017, 5:32pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/16 "2017-09-10T17:32:56Z")

</div>

I can comment here once moar, that swift have better design in this question  
use if instead of ternary operator allowed this brackets hollywar to be,  
even this looks better

```kotlin
val x = if bolean ? somevalue else someotther
```

---

<div class="post-metadata">

**Author:** ![Avarel](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/avarel/32/3917_2.png) [@Avarel](https://discuss.kotlinlang.org/u/Avarel)\
**Post date:** [September 10, 2017, 7:23pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/17 "2017-09-10T19:23:37Z")

</div>

Parentheses lead to clarification of syntax necessary in order to do Kotlin lambda parameters/builders. Assuming that `higherOrderFunction(function)` returns a boolean, this clarifies the intent clearly.

```kotlin
if (higherOrderFunction { doSomething() }) 3 else 2

```

On the other hand, this is extremely ambiguous.

```kotlin
if higherOrderFunction { doSomething() } 3 else 2

```

---

<div class="post-metadata">

**Author:** ![Redrield](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@Redrield](https://discuss.kotlinlang.org/u/Redrield)\
**Post date:** [September 12, 2017, 3:07pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/18 "2017-09-12T15:07:20Z")

</div>

There is no reason to complicate the frontend of the compiler, make it harder to maintain, and harder to understand, just because you think round brackets look ugly.

---

<div class="post-metadata">

**Author:** ![kojiba](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/kojiba/32/3596_2.png) [@kojiba](https://discuss.kotlinlang.org/u/kojiba)\
**Post date:** [September 13, 2017, 4:39pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/19 "2017-09-13T16:39:05Z")

</div>

U don’t understand language design, its not about compiler frontend complexity, its about brevity of language creating, if we care about complexity, people must be programing on C now, and not on Ruby/Rust/JS/Swift/etc

---

<div class="post-metadata">

**Author:** ![Redrield](https://avatars.discourse-cdn.com/v4/letter/r/ad7895/32.png) [@Redrield](https://discuss.kotlinlang.org/u/Redrield)\
**Post date:** [September 13, 2017, 5:08pm UTC](https://discuss.kotlinlang.org/t/remove-if-branches-or-make-optional/4233/20 "2017-09-13T17:08:08Z")

</div>

You missed my point. It makes the compiler more complex and provides no tangible benefits to the programmer.
