TicTacToe in Bosque and Kotlin

From Discover on Google https://www.jworks.io/tictactoe-in-bosque-and-kotlin/

Microsoft Bosque is the latest language, Kotlin is Google supported Java-compatible language.

Advertisements

Kotlin FP: Interface vs Extension

When more specific behavior needed, use “interface”.

eg. Interface Vehicle: drive()

-> car.drive ();

-> motorcycle.drive ();

If it is a common general behavior, use extension.

https://blog.oozou.com/interface-in-kotlin-and-when-to-use-it-5d32caab19be

Kotlin: Co-Variance, Contra-Variance, Invariance, Immutability

Kotlin is a functional programming (FP) language which has the Category concept of co-Variance, contra-Variance. Java is object-oriented not FP, it has only Invariance.

https://dzone.com/articles/variance-immutability-and-strictness

Note:

Covariance and contravariance are terms that refer to the ability to use a less derived (less specific = CoVariance eg. Apple instead of Fruit) or more derived type (more specific = ContraVariance, eg. Gala instead of Apple) than originally specified.

Generic type parameters support covariance and contravariance to provide greater flexibility in assigning and using generic types.

  • Invariance

    Means that you can use only the type originally specified; so an invariant generic type parameter is neither covariant nor contravariant. (Java is always invariance.)