Why `fun`?

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?

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.

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.


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.


Should have used function, func or fn, just saying, it would have been a better larger audience choice.

SML is using fun. The audience coming from there has no quantitative relevance… Quality over quantity in this case :joy:

I heard in the recording of some conference that fun is used because it’s 3 letters long like var and val. :smiley:

1 Like