I'm a Kotlin developer. What are the similarities and differences with EK9?

← Getting Started · Ref: Q1007

EK9 and Kotlin share several design decisions:

SAME: CLOSED BY DEFAULT

Kotlin classes are final by default (use 'open' to extend). EK9 classes are closed by default (use 'as open' to extend). Same concept, slightly different keyword.

SAME: NULL SAFETY

Kotlin has nullable types with ?. and ?: operators. EK9 has tri-state with ? suffix and ?? coalescing. Both prevent null pointer exceptions at compile time.

SAME: DATA CLASSES / RECORDS

Kotlin 'data class' auto-generates equals/hashCode/toString/copy. EK9 'defines record' with 'default operator' auto-generates the same set of operators.

DIFFERENT: NO RETURN

Kotlin has return. EK9 declares return variable with <- in the signature. No return keyword.

DIFFERENT: STREAM SYNTAX

Kotlin uses method chaining: list.filter { }.map { }.toList(). EK9 uses pipe syntax: cat list | filter by fn | map with fn | collect as List of T.

DIFFERENT: DECLARATION

Kotlin uses val/var keywords. EK9 uses <- operator for declaration, := for reassignment.

DIFFERENT: SWITCH

Kotlin 'when' is an expression. EK9 'switch' is also an expression — similar concept.

Example

defines module qa.gettingstarted.fromkotlin

  defines record

    //Like Kotlin: data class Coordinate(val latitude: Float, val longitude: Float)
    Coordinate
      latitude as Float: 0.0
      longitude as Float: 0.0

      Coordinate()
        ->
          latitude as Float
          longitude as Float
        this.latitude :=: latitude
        this.longitude :=: longitude

      //Like Kotlin's auto-generated equals/hashCode/toString/copy
      default operator

  defines program

    FromKotlinDemo()
      stdout <- Stdout()

      //Like Kotlin: val point = Coordinate(51.5, -0.1)
      point <- Coordinate(51.5, -0.1)
      stdout.println($point)

      //Like Kotlin: if (value != null) — EK9 uses ? suffix
      if point?
        stdout.println("Point is set")

      //Like Kotlin: val other = point.copy() — EK9 uses :=: operator
      other <- Coordinate(0.0, 0.0)
      other :=: point
      stdout.println($other)
Other ways to ask this
  • How does EK9 compare to Kotlin?
  • What will feel familiar to a Kotlin developer in EK9?
  • Kotlin to EK9 — what's the same and what's different?

Coming from another language?

Kotlin developers will find EK9 familiar: closed types, null safety, data classes. The main adjustment is no return keyword and pipe syntax for streams.

Keywords: null safety, when, closed, migration, kotlin, data class, record