KOTLIN

AND

STATE OF WEBASSEMBLY

Kotlin

What is Kotlin?

Why Kotlin?

Pros and Cons

 

WASM

Current State

WASM + Kotlin

Kotlin

What is it?

Island!

Statically typed programming language
for modern multiplatform applications

FEATURES

Ultra-multi-platform

Concise
Safe
Interoperable

Functional yet static typed

fun main(args: Array<String>) {
    val oddLength = compose(::isOdd, ::length)
    val strings = listOf("a", "ab", "abc")
    println(strings.filter(oddLength))
}

fun isOdd(x: Int) = x % 2 != 0
fun length(s: String) = s.length

fun <A, B, C> compose(f: (B) -> C, g: (A) -> B): (A) -> C {
    return { x -> f(g(x)) }
}

Null Safety

fun parseInt(str: String): Int? {
    try {
        return str.toInt()
    } catch (e: NumberFormatException) {
        println("One of the arguments isn't Int")
    }
    return null
}

fun main(args: Array<String>) {
    if (args.size < 2) {
        println("No number supplied");
    } else {
        val x = parseInt(args[0])
        val y = parseInt(args[1])

        if (x != null && y != null) {
            print(x * y) // Now we can
        } else {
            println("One of the arguments is null")
    }
    }
}

Elvis Operator

val l: Int = if (b != null) b.length else -1
// equals to
val l = b?.length ?: -1

if - expression

val max = if (a > b) a else b

val max = if (a > b) {
    print("Choose a")
    a
} else {
    print("Choose b")
    b
}

for loop

for (item in collection) print(item)
for (item: Int in ints) {
    // ...
}
for (i in array.indices) {
    print(array[i])
}
for ((index, value) in array.withIndex()) {
    println("the element at $index is $value")
}

when

fun main(args: Array<String>) {
    cases("Hello")
    cases(1)
    cases(0L)
    cases(MyClass())
    cases("hello")
}

fun cases(obj: Any) {
    when (obj) {
        1 -> println("One")
        "Hello" -> println("Greeting")
        is Long -> println("Long")
        !is String -> println("Not a string")
        else -> println("Unknown")
    }
}

class MyClass() {
}

HTML builder,  ts2kt, coroutines, destructuring, delegate, callable references and much more (even native canvas support!)

WebAssembly

RoadMap

 

  • April 2015 - WebAssembly Community Group started
  • June 2015 - The first public announcement
  • March 2016 - Definition of core feature with multiple interoperable implementations
  • October 2016 - Browser Preview announced with multiple interoperable implementations
  • February 2017 - Official logo chosen
  • March 2017 - Cross-browser consensus and end of Browser Preview

Current State

WASM is Already in Your Browsers!

+

= ?

DISCLAIMER!

All my next words, is only my personal opinion about topic subject, it's not even close an "expert opinion", or not intended to harm someone's tender feelings. So If you feelings will be harmed nevertheless, just live with that, and remember - they watching you...

Conclusion

Thank for your attention!

Kotlin And WebAssembly

By diodredd

Kotlin And WebAssembly

  • 745