Let us make a mess

Local functions

Local functions are good for code reuse, just be careful not to overuse them to avoid confusion.

fun foo(a: Int) {

fun local(b: Int) {

return a + b

} return local(1)

}

Infix functions

Infix functions are good for readability, because it allows typing something like "test" foo "x" for example, pretty cool eh!

infix fun String.foo(s: String) {

...

} // Call extension function.

"test".foo("x") // Or call extension function using infix notation.

"test" foo "x"

Infix functions must have a single parameter.

Inline functions

A lambda expression in Kotlin is translated to Java anonymous classes in Java 6 or 7, that is an overhead. Lambda calls are affecting the call stack which has a performance impact.

inline functions can be used to flat out calls instead of invoking another method call and adding that to the call stack. So it makes sense to use inline functions when we pass in the lambdas.

inline fun callBlock(block: () -> Unit) {

println("Before calling block")

block()

println("After calling block")

}

When we call callBlock it gets translated to something like the following:

callBlock { println("The block operation") } // Rough java bytecode

String var1 = "Before calling block";

System.out.println(var1)

String var2 = "The block operation";

System.out.println(var2);

var1 = "After calling block";

System.out.println(var1);

vs. the following if the function was not marked as inline

callBlock { println("The block operation") } // Rough java bytecode

callBlock((Functinos0)null.INSTANCE);

You have to be careful with inline functions though because it literary copies the method content where it is called and if the body of the functions is too large you really do not want to do this.

Knowing that, the following obviously will not make any sense because it has zero effect.