Refactoring to Expressive Kotlin | Dmitry Kandalov and Duncan McGregor

Поділитися
Вставка
  • Опубліковано 17 вер 2024
  • Recording brought to you by American Express. americanexpres...
    Kotlin was built from the beginning as an expressive language, but we still scratch our heads when reading some code, especially if it is trying to do something complicated.
    Join Duncan and Dmitry as they examine code examples and use the power of the Kotlin language and IntelliJ to refactor them into code that reads as it works. We’ll learn how to express intent with the scope functions: let, run, with, apply, and also. We’ll see how defining our own extension functions allows code to flow, and move on to more advanced topics like separating pure from impure functions, cohesion, tiny types and domain specific languages.
    #kotlin #kotlinconf

КОМЕНТАРІ • 11

  • @mytubekt
    @mytubekt Місяць тому +2

    Very nice talk! Thanks for sharing.

  • @JPilsonSumbo
    @JPilsonSumbo Місяць тому +16

    Fun to watch

  • @three-alpha-six
    @three-alpha-six Місяць тому +19

    That definitely was the most excruciating rename of a simple function that wasn’t even necessary in the first place.

    • @GeorgeC-ur9yw
      @GeorgeC-ur9yw Місяць тому +1

      at least it was not put into a separate module with abstraction following all the best practices/industry standards of clean architecture

    • @andreroodt4647
      @andreroodt4647 Місяць тому

      It's great for hourly contractors. Adding this to my toolbox for sure. 🙂

  • @emmanuelmtali1594
    @emmanuelmtali1594 Місяць тому +1

    You wasted my time a little bit 🤕 (Renaming)

  • @lppedd
    @lppedd Місяць тому +6

    I always *beg* my fellow devs not to use also, apply, let (or other scope functions). They make the code a PITA to read.

    • @hkupty
      @hkupty Місяць тому +2

      It's interesting that it isn't a consensus on whether it makes the code more or less readable to use those scope functions. I've found situation where it made sense to use them and definitely situations where it doesn't. The big value of the refactoring they made, to me, was the decoupling, not the readability, but readability is so intrinsically connected to familiarity with the code base, the language and the common standards that I don't see this as a bad thing, inherently. I wonder if the kotlin compiler yields the same bytecode in the end, inlining those extra functions and lambdas...

    • @lppedd
      @lppedd Місяць тому +1

      @@hkupty yeah the bytecode is the same. Although I'm not sure about non-jvm platforms, especially when creating a standalone binary.
      Kotlin's goal is to be readable, and most of the times those scope functions are abused. I'm OK on using them when initializing a property, for example, so that I clearly see what's going on in that block.

    • @kyay10
      @kyay10 Місяць тому

      @@lppedd If it's bad on non-JVM platforms, that's definitely a missing optimization and should be reported

    • @tompov227
      @tompov227 Місяць тому

      Interestingly I find let very confusing by I like with, apply, and especially also