Skip to content

Instantly share code, notes, and snippets.

@lyqht
Last active October 6, 2022 09:46
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyqht/d4518efbbe47753fdb6ead6bf1f76748 to your computer and use it in GitHub Desktop.
Save lyqht/d4518efbbe47753fdb6ead6bf1f76748 to your computer and use it in GitHub Desktop.
GDG SG X Kotlin User Group SG - Kotlin/Everywhere Meetup 2019

Kotlin/Everywhere

A summary on the talks that happened in GDG SG X Kotlin User Group SG - Kotlin/Everywhere Meetup on 24 September 2019.

Talks:

Please shoutout to me or help to improve these notes by commenting below if you noted down something relevant that I missed out here! I am aware that some Q&A are missed out, and this is because I am not knowledgeable enough in Kotlin to understand what is being mentioned.

EDIT LOG

  • 26/9/19: Saurabh Arora helped to make changes to the points for his talk!

Kotlin on Android: A look to the Future

Speech by Karen Ng from USA, Google

Why Kotlin for Android

  • Accelerate Android development by making high-quality apps easier
    • with a modern, concise & expressive language
    • safer code and require less boilerplate
  • There used to be a lot of debate whether Kotlin would be added as a first-class language right before the Google I/O speech 2017
    • In I/O 2019, Kotlin is also an official language inside Google and Android Development
  • As of 2019 Stats:
    • 53% of professional developers are using Kotlin for Android
    • 32% using Kotlin as primary language
    • 50% of top 1000 apps on Play store are using Kotlin

Future development

Confirmed:

  • Continue work on build speed
  • Kotline IDE Support
  • Annotation processor alternative

Embrace Kotlin-firs everywhere including Jetpack libraries. e.g. Android Jetpack v4.0, Jetpack Compose

Q&A

Q. Google also developing on Flutter, so how about Android Jetpack Compose development in the future? A.

  • Android supported languages: C++, Kotlin, Java
  • Jetpack compose actually partner with Flutter.
    • Flutter has great and simple React APIs, so they want to make it that way also for the Android Jetpack Compose.
    • In the Android development ecosystem, Jetpack Compose still has a place since there might be developers who still need to develop specifically for Android

The cost of Nullability in Kotlin

Speech by Saurabh Arora

  • Primitives cannot have null value by default, so the compiler by default does not check if such variables are nullable.
    • Unless you indicate the primitive as nullable, then the compiler will check for it intentionally, and this may result in autoboxing.
  • Lazy variable handling
    • Accepts a parameter to do synchronization
    • Might also perform autoboxing for many variables if there are variables are declared to be possibly nullable
    • Any better way to optimize: By default, Thread safety mode is supposed to LazyThreadSafetyMode.NONE and not null. So if you know for certain that function runs on a single thread then can pass it thread safety mode to null to improve performance
  • Arrays are mapped differently in Kotlin
    • e.g. Array<Int> -> Integer[]
    • e.g. IntArray -> int[]
  • If Java did not have any annotation, there might still be a chance for the Kotlin variables to be null
    • If you are parsing API response and your Kotlin variable is defined as non-null, you can use a serialization library to assign it a default value to avoid it trying to store null

Side comments:

  • Premature Optimizations is the root of all evil, but it does not mean that you don't do it, just be aware of what actually happens.
  • We should not sacrifice null safety to avoid autoboxing

Kotlin Gotchas

Speech by Marcel Pinto Biescas.

Git Repo containing code for concepts discussed below will be uploaded by Marcel later, I'll post a link to it when it's done.

  1. The difference between list.add(x) and list.plus(x)

    • plus creates a new list after adding an element to the list
    • add only adds an element to the list
  2. The difference in initializing the variables by var list and val list

    • val list: cannot add element to the list if the variable is declared to be final
    • var list: can add if make the list
  3. Nullability Gotchas: Using requireNotNull(x) {} and x!! on a nullable variable if the variable is applied as a variable to a function that does not accept nullable parameters.

    • Be careful of concatenation of many .run{}
    • There is a good graph that describes when to use a certain gotcha
  4. lateinit

    • (::some.isInitialized)
    • if need many lateinit, should just declare it nullable
  5. Overriding the get() function of a variable

    • get() takes priority over the override keyword when applied to interface variables in classes.
    • use of init { } for initializing variables inside a class
@LiewJunTung
Copy link

Join the Kotlin Slack Group #Singapore channel here! https://slack.kotlinlang.org

@nghianja
Copy link

Join the Kotlin Slack Group #Singapore channel here! https://slack.kotlinlang.org

Still waiting for the invite...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment