# "def" vs. "fun"

**URL:** <https://discuss.kotlinlang.org/t/def-vs-fun/1261>\
**Category:** Uncategorized\
**Created:** [March 11, 2012, 4:46pm UTC](https://discuss.kotlinlang.org/t/def-vs-fun/1261 "2012-03-11T16:46:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ae6rt](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ae6rt/32/1591_2.png) [@ae6rt](https://discuss.kotlinlang.org/u/ae6rt)\
**Post date:** [March 11, 2012, 4:46pm UTC](https://discuss.kotlinlang.org/t/def-vs-fun/1261/1 "2012-03-11T16:46:03Z")

</div>

I'm not trying to open a can of worms ([http://en.wiktionary.org/wiki/can\_of\_worms](http://en.wiktionary.org/wiki/can_of_worms)) here, but the folks on the very-widely-listened-to JavaPosse raised a reasonable question about the Kotlin keyword "fun" vs. "def" to introduce a function definition.&nbsp;&nbsp;I thought the question was good enough to warrant at least one airing here.

Scala and Groovy use “def” for functions.&nbsp;&nbsp;Might Kotlin reduce the impedance mismatch for users coming from those language to Kotlin by using def instead of fun, too?&nbsp;&nbsp;I don’t feel strongly about it.&nbsp;&nbsp;Just asking.

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [March 11, 2012, 5:07pm UTC](https://discuss.kotlinlang.org/t/def-vs-fun/1261/2 "2012-03-11T17:07:26Z")

</div>

The most obvious reason is that "fun" speaks for itslef: you need no manual to find out what it stands for. There are some more reasons.

In Scala and Groovy “def” means something different than “fun” in Kotlin. These languages denote “function or property” by “def”. Groovy even uses “def” for local variables.  
In Kotlin “fun” is strictly a function.

One other thing is that “def” stands for “definition”, which a “def” sentence might not necessarilty denote: it may denote a declaration instead.

---

<div class="post-metadata">

**Author:** ![cedricbeust](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/cedricbeust/32/1429_2.png) [@cedricbeust](https://discuss.kotlinlang.org/u/cedricbeust)\
**Post date:** [March 11, 2012, 9:08pm UTC](https://discuss.kotlinlang.org/t/def-vs-fun/1261/3 "2012-03-11T21:08:32Z")

</div>

Hi Andrey,

Any reason why we couldn’t have just one keyword for both concepts?

I don’t see much user benefit to having two keywords (Scala fell in the same trap in a worse way with the equal sign and also :Unit, it would be nice not to repeat that mistake).

–  
Cédric

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [March 12, 2012, 1:23pm UTC](https://discuss.kotlinlang.org/t/def-vs-fun/1261/4 "2012-03-12T13:23:50Z")

</div>

> Any reason why we couldn't have just one keyword for both concepts?

One big reason: pedagogical. Don't name apples grapes, for they are apples, not grapes.

> I don't see much user benefit to having two keywords (Scala fell in the same trap in a worse way with the equal sign and also :Unit, it would be nice not to repeat that mistake).

Could you explain this? Thanks

---

<div class="post-metadata">

**Author:** ![cedricbeust](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/cedricbeust/32/1429_2.png) [@cedricbeust](https://discuss.kotlinlang.org/u/cedricbeust)\
**Post date:** [March 12, 2012, 7:12pm UTC](https://discuss.kotlinlang.org/t/def-vs-fun/1261/5 "2012-03-12T19:12:51Z")

</div>

I realize I misread the discussion and/or the documentation, I was under the impression that fun was used to declare functions and def for void methods. I tried to find the meaning of these two keywords in the documentation but came up empty.

fun is for introducing functions, what is def for? Is it even a valid Kotlin keyword? The only traces I found were in comments on the wiki, so obviously not trustworthy.

Side remark: the search feature of this web site should _not_ produce results from comments, it introduces too much confusion. When I’m looking for something about the language, I only want to search through the official reference manual, not random comments by people who are arguing about hypothetical stuff.

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [March 13, 2012, 5:07pm UTC](https://discuss.kotlinlang.org/t/def-vs-fun/1261/6 "2012-03-13T17:07:25Z")

</div>

> fun is for introducing functions, what is def for? Is it even a valid Kotlin keyword? The only traces I found were in comments on the wiki, so obviously not trustworthy.

"def" is not a keyword in Kotlin.

> Side remark: the search feature of this web site should \*not\* produce results from comments, it introduces too much confusion. When I'm looking for something about the language, I only want to search through the official reference manual, not random comments by people who are arguing about hypothetical stuff.

Unfortunately, I don't know how to make Confluence search in pages only by default. You can use the detailed search settings on the serach results page.

---

<div class="post-metadata">

**Author:** ![cedricbeust](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/cedricbeust/32/1429_2.png) [@cedricbeust](https://discuss.kotlinlang.org/u/cedricbeust)\
**Post date:** [March 13, 2012, 6:16pm UTC](https://discuss.kotlinlang.org/t/def-vs-fun/1261/7 "2012-03-13T18:16:14Z")

</div>

> "def" is not a keyword in Kotlin.

Thanks for confirming.

> Unfortunately, I don't know how to make Confluence search in pages only by default. You can use the detailed search settings on the serach results page.

It’s a pity that Confluence won’t even weigh the results so that hits on pages appear before hits on comments.
