From 5e6ad57d2ee382aa911a9d409ca336961cca0cd8 Mon Sep 17 00:00:00 2001 From: Danilo Pianini Date: Sun, 16 Aug 2020 23:13:55 +0200 Subject: [PATCH] Write down a plan --- slides/content/01-kotlin/_index.md | 164 +++++++++++++++++++++++++++-- 1 file changed, 158 insertions(+), 6 deletions(-) diff --git a/slides/content/01-kotlin/_index.md b/slides/content/01-kotlin/_index.md index 986d8fbe..db8ac7ff 100644 --- a/slides/content/01-kotlin/_index.md +++ b/slides/content/01-kotlin/_index.md @@ -68,21 +68,33 @@ Similar to Scala. The keyword `def` is replaced by `fun` val x = 10 // constant var y = 20 // variable, can be reassigned fun foo() = 20 // function definition, single expression -fun foo() { // same as above with multiple expression - return 20 // requires return in this form +fun bar(): Int { // same as above with multiple expression + return 20 // requires a return in this form... } +fun baz() { } // Unless it returns Unit + ``` --- # Kotlin 101 -## Function parameters, return types +## Function parameters and return types Much like Scala: +* All parameters are named, but can be invoked positionally as well +* Parameters can have defaults +* Types are annotatedd after the parameter name +* Invocation can be positional or by name, with the rule that once a named parameter is used, subsequent parameters must be named as well + ```kotlin -fun foo(): Int = 10 // types are annotated with a column and the type name -fun foo() = 10 // return type annotation can be omitted (if the compiler can infer it) +fun foo(a: Int, b: String): Int = TODO() // TODO() is a builtin +// MANCANO I DEFAULT!!!! +function throwing a `NotImplementedError` +foo(1, "bar") // OK, positional +foo(a = 1, b = "bar") // OK, named +foo(1, b = "bar") // OK, hybrid +foo(a = 1, "bar") // error: no value passed for parameter 'b' ``` --- @@ -129,4 +141,144 @@ fun main(arguments: Array) = println("Hello World") // Valid entry point fun main(arguments: Array) { println("Hello World") // Return type is Unit, no need to return } -``` \ No newline at end of file +``` + +--- + +# Kotlin 101 +## Program entry point + + +--- + +# TODOS + +## 101 +type hierarchy (top and bottom types) +nullable types +boolean types +numeric types +unsigned integers +string templates +multiline strings +packages and imports +compile time constants +varargs +infix +local functions +inline functions + +## flow control +if +for +while +break and continue +when vs. pattern matching +labeled jumping (incl. qualified return) + +## oop +classes and members (methods and properties) +object creation (no new) +access to members (invoke vs named access) +inheritance and open +inheritance and override +abstract +inheritance and disambiguation by `super` +interfaces and subtyping +implementation of members in interfaces (no backing field) +constructors +init blocks +secondary constructors +nullability and `lateinit` +getters +setters +accessors in interfaces +backing fields, `field` +objects +companion objects +visibility +controlling visibility of properties (`private set`) +equality / hashing / toString + +## generics +syntax for functions +syntax for classes +type bounds +`where` +variance +use site variance and type projection +declaration site variance +star-projection +reified types +invocation of reified types + +## basic collections? +list / mutablelist +set / mutableset +map / mutablemap +`in` + +## extended OOP +data classes +copy / equals / toString +destructuring declarations +Pair / Triple +sealed classes +sealing and when +nested classes +inner classes +enum classes +anonymous classes via object expression +type aliasing +delegation and `by` +contract implementation by delegation (favor composition over inheritance) +delegated properties and variables +delegated properties https://kotlinlang.org/docs/reference/delegated-properties.html +lazy +observable +delegation via map (mutability via MutableMap) +implementing a custom delegate for properties + +## functional kotlin +function types +function types and nullability +lambda expressions +trailing lambdas +implicit single parameters +closures +destructuring in lambdas +anonymous functions (rarely used) +invoke convention +inline functions + +## extensions +extension functions vs implicits +extension properties (no backing field) +nullable receivers +companion extensions +generic extensions +extensions resolution +extension members (scope control) +visibility of private members + +## extensions + functional +function types with receiver + +## standard library +let / run / apply / with +arrays +primitive arrays +ranges + +## performance +tail recursion +inline functions +noinline +crossinline +inline classes -- mentioned and skipped, ref to https://kotlinlang.org/docs/reference/inline-classes.html + +## java interop +@JvmOverloads +@JvmDefault + +## DSLs in Kotlin (type-safe builders) \ No newline at end of file