Why `fun`?


#1

Methods are declared with the fun keyword in Kotlin, whereas most other languages use def (e. g. Scala, Python) some use fn (e. g. Rust) or function (JavaScript). I wonder whether it was intended or at least a welcome sideeffect to have the word “fun” in the language :wink: Was it?


#2

It took me a while to get used to fun, and I would have preferred the straight-forward function. (If override and companion object aren’t considered too long, function shouldn’t either, even though it’s used more often.) One nice aspect (if you will) is that fun, val, and var all have the same length, but I don’t know if that played a role in the decision.

PS: JavaScript uses function.


#3

I don’t think there’s any word for defining functions that “most” languages use. We use “fun” because we like it - and yes, we do know what the word means in English.


#4

I think there is some masterful psychological manipulation going on here. Every time you write a function in Kotlin they want you to believe you’re having fun.

I mean, think about it… all the awesome stuff they’ve done with the language; it’s like they want you to enjoy yourself while programming. Having fun while programming, absurd.