ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Follow publication

Noisy Code 🗣 With Kotlin Scopes

Chetan Gupta
ProAndroidDev
Published in
6 min readApr 4, 2021

--

Scopes make your code more readable? think again

You are going to encounter these scope functions namely let, run, apply, also, within every Kotlin codebase, along with all the mischievous ways developers exploit their usage from the way they were intended for. Let see how popular opinion on those ends up just as a code noise.

Don’t miss out on the course on Generative AI using Kotlin, Jetpack Compose, Langchain4j, and Ollama. You will learn hands-on by building 6 AI apps. Join now for lifetime access, but hurry — prices increase after July 1st!

Featured On

Don’t miss out on the course on Generative AI using Kotlin, Jetpack Compose, Langchain4j, and Ollama. You will learn hands-on by building 6 AI apps. Join now for lifetime access, but hurry — prices increase after July 1st!

Let me out! ⛓

Popular opinion → let is treated as a native way to do null checks on the variables.

Please don’t do that even if using `let` feels functionally beautiful but

  • You will end up creating another reference called it in the same scope which is less descriptive
  • To fix that you will definitely try to provide an explicit parameter for lambda example imageFile?.let{ image →,
  • but it creates a load of finding another name for the same variable (naming things are hard)
  • Now other devs can refer to image files in the scope with two names…

--

--

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

Written by Chetan Gupta

Android & Kotlin Expert | Training & Technical writing for Bussiness contact https://t.me/ch810

Responses (6)

Write a response