Skip to content

Instantly share code, notes, and snippets.

@aksh1618
Last active July 24, 2021 12:36
Show Gist options
  • Save aksh1618/2ae7f71aa2540a38787682a04af23e3f to your computer and use it in GitHub Desktop.
Save aksh1618/2ae7f71aa2540a38787682a04af23e3f to your computer and use it in GitHub Desktop.
Kotlin 1.4 Online Event Summary

Day 1

  • KMM: Kotlin Multi platform for Mobile
  • New front ends and backends
  • Enable data sharing in IntelliJ
  • Answer questions on SO
  • Interfaces can be fun now! SAM conversion, but explicit
  • Explicit API Mode: Errors/Warnings enforcing explicit visibility and return types (for libraries, preventing accidental exposure/breakage)
  • Trailing, commas,
    • But don't be tempted to just swap argument lines, use IDE refactoring to properly handle usages!
  • continue and break allowed now in when inside loops
  • named and positional args can now be mixed!
    • but take care to maintain the order!
  • Better type inference!
    // 1.3 -> result: String!
    // 1.4 -> result: String
    val result = run {
        var str = getNullableString()
        if (str == null) {
            str = "test"
        }
        str
    }
  • References with default args!
    fun foo(i: Int = 0): String = "$i!"
    fun apply(f: () -> String): String = f()
    apply(foo) // 0!
  • KotlinNullPointerException (!!), TypeCastException (as Type), IllegalStateException (platform-type expression), IllegalArgumentException(parameter) -> NullPointerException
  • @JvmDefault no longer required for using java 8's interface default methods
  • Speeeeeeeedddddd!!!!!
    • make sure to update intellij
  • Kotlin plugin is becoming a part of intelliJ !!!
    • That means features like chain intermediate return types etc. can come together for Java & Kotlin!!
  • interop will continue for new Java versions
  • How things get decided: Slack/Forums, Comm with big users, YouTrack, Keep
  • Feature propagation: Ideas/Proposals: YouTrack #{language design} -> Design document: KEEP -> Corrections/improvements: KEEP Issues
  • Vote for KT-14663 :p (different type for different visibility for properties)
  • More stuff:
    • Namespaces & extensions
    • multiple receivers & decorators
    • public/private property types
    • ternary operators (bool ? true : false syntax declined)
    • immutability & inline classes

Day 2

  • Debugging improvements in IntelliJ
  • StateFlow! Design (Looks similar to LiveData?)
  • SharedFlow!! Design
  • Core operators and invariants
    • Limited building-block core operators
    • Better exceptions on violating rules
  • Android Improvements
  • runInterruptible for blocking Java code
        withTimeout(500.milliseconds) {
            runInterruptible(Dispatchers.IO) {
                blockingQueue.take()
            }      
        }
  • Support for BlockHound and Java 9 Flow!!
  • Why?
    • Multi platform, kotlin oriented (such as default value support, reified goodness)
  • Configuration using DSL (future-proof, binary-compatible)
  • Some advanced features and formats are experimental
  • coerceInputValue: support default values in deserialization
  • more flexible polymorphic deserialization
  • Behind the sscenes: KotlinConf 2019: Design of Kotlin Serialization by Leonid Startsev
  • Consistency:
    • *OrNull: randomOrNull, maxOrNull, maxByOrNull, minOrNull, minByOrNull
      • maxOf -> returns the max value (where as maxBy return element with max value)
    • *Indexed: onEachIndexed, flatMapIndexed
      • reduceOrNull, reduceIndexedOrNull
  • runningReduce & runningFold: each intermediate value (kinda like KTable)
    (1..5).reduce { sum, elem -> sum + elem }        // 15
    (1..5).runningReduce { sum, elem -> elem + sum } // [1, 3, 6, 10, 15] 
  • ArrayDequeue (uses circular buffer internally, so adding element to begin is mostly constant
  • bit manipulation: countOneBits, countTrailingZeroBits, takeHighestOneBit)
  • stdlib dependency included by default
  • @Kotlin.Throws for interop with all platforms
  • Experimental
    • @RequiresOptIn/@OptIn
    • Collection Builders: similar to buildString (Mutable while building, returning immutable)
    • time measurement: measureTime (returns Duration, which is inline class), TimeSource, measureTimedValue -> Pair<T, Duration>
  • Types & Operations:
    • Instant (Physical), LocalDateTime/LocalDate (Civil)
    • Arithmetic: plus, minus, until, periodUntil
    • Helper Type: DateTimeUnit, DateTimePeriod/DatePeriod, Month, DayOfWeek
  • Converters to/from java.time.*
  • Future: serialization, formatting & parsing (in english first), ranges (starDate..endDate), embedded TZDB for consistency

Day 3

  • KSP (Kotlin Symbol Processing): Alternative to KAPT, 30-40% faster, developer preview currently
  • Kotlin metadata preservation in AGP to support kotlin-reflect, R8 etc.
  • Coroutine support in room, work manager, paging, data store, compose etc.
  • Improved webpack support
  • Improved npm support: Dukat
  • kotlinx-nodejs (experimental): Type safe access to Node.js API from Kotlin/JS
  • Coming with IR Compiler: Smaller bundles, @JsExport & Typescript definitions
  • Looking at WebAssembly
  • Multi level heirarchy
  • Publishing
    • Intermediate sources also need to be published
    • .kotlin_metadata format (serialized declarations) used by common has limitations (no method bodies)
    • Hi klib!
      • Normal zips, contain kotlin_metadata + bodies in IR (~ serialized ASTs)
  • Dependency Management
    • Variants in .module file
    • Allows dependency inference magic
  • Commonizer
    • Extracts intersecting API
    • Enables shared native libraries
  • Florina: Data Layer/Room: Live Data or Flow?
    • Prefer flow as it has more flexible operators and doesn't return on main thread like LiveData
  • Florina: Will LiveData be deprecated in favor of Flow?
    • Not yet, because not supported everywhere yet (fixable) and lifecycle awareness (fixable??)

Day 4

  • https://spring.io/guides/tutorials/spring-boot-kotlin/
  • Already part of documentation
  • Supported in MVC & WebFlux
    • Coroutines support in WebFlux, MVC support coming with 2.4
    • Annotations & Functional
  • First class coroutines support also in Data, Messaging & Vault
  • kotlinx.serialization supported starting 2.4!
  • 100% of spring framework API now has null-safety annotations
  • Rsocket kotlin (multiplatform with coroutines) rebooted
  • @ConfigurationProperties works with data classes with val properties using @ConstructorBinding
  • DSL for spring security
  • Team size quadrupled, twitter account (@JetBrainsKtor), semver
  • CIO engine for server: Coroutines IO
  • Module Request -> Routing | -> App Logic | -> Response (Feature) (Feature) (Encoding) (Compression)
  • Features are like interceptors, such as default headers, content negotiation, authentication
  • Custom features supported, API being improved
  • Structure as it suits you; related post by Hadi
  • Improvements in store, including onboarding, tooling and documentation
  • ktor.io
  • Serverless
    • Pro: Pay per use, scalable, fault-tolerant
    • Con: Tons of configurations
  • Ktor deduces configuration from code, for..
    • multiple frameworks: spring, ktor, DSL ;
    • multiple runtimes: JVM, GraalVM, JS* ;
    • multiple clouds: AWS, GCP*, Azure* *: Under development
  • Supports local cloud emulation (using localstack)
  • Under the hood: Parses application -> cloud agnostic schema -> transpiled to and deployed using terraform
  • Cloud integration: permissions/events using annotations
  • Future:
    • Toolin in IDEA: remote logs tailing and debugging
    • More cloud-specific extensions
Day-wise summaries of talks of the Kotlin 1.4 Online Event
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment