Remove if branches, or make optional


#1

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


Feature Request: Removing parentheses for for-loop
#2
  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.

#3

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.


#4

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?


#5

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


#6

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.

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

#7

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

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.


#8

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.

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.


#9

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


#10

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


#11

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?


#12

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


#13

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.


#14

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.


#15

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


#16

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

val x = if bolean ? somevalue else someotther

#17

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.

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

On the other hand, this is extremely ambiguous.

if higherOrderFunction { doSomething() } 3 else 2

#18

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.


#19

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


#20

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