Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why didn't Kotlin follow Java syntax?

Tags:

kotlin

I'm in the process of learning Kotlin as an Android developer!

Out of curiosity, why didn't the JetBrains guys follow the Java style syntax (where they could have), and made it easier on developers to learn Kotlin?

For example, defining a simple function in Kotlin:

fun simpleFunc(x: Int): Int {

// do stuff

}

Why didn't they do:

fun Int simpleFunc(Int x) {

// do stuff

}

I would appreciate hearing your opinion on this

like image 242
TareK Khoury Avatar asked May 19 '26 09:05

TareK Khoury


1 Answers

As mentioned in the Kotlin FAQ, Kotlin's syntax makes it more natural to omit type declarations when they can be inferred by the compiler (which isn't supported by Java). Also, from our experience with Kotlin, we see no evidence that Kotlin's type declaration syntax presents a difficulty for people learning Kotlin.

(Note that your suggested syntax is also different from Java, so it's not clear why you think it would be easier to learn.)

like image 89
yole Avatar answered May 21 '26 02:05

yole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!