Generalising all the things - Expert Kotlin Refactoring

Опубликовано: 10 Май 2024
на канале: Pairing with Duncan
634
39

In this mini-series we’ve been comparing Ktor (https://ktor.io/) with http4k (https://http4k.org), and now I’d like to be able to compare their throughput. I have some benchmarking code left over from the coroutines and Loom episode (   • Kotlin Coroutines and Loom  ), so it would be nice to use that, but it is very much specialised to http4k.

I suppose that I could just copy it for Ktor and then make edits, but where would the fun in that be? So today we’re going to look at how to progressively refactor a method into a function, and then to generalise all the things so that it no longer depends on any http4k types, and we can use it in other situations.

Oh and have IntelliJ automatically update the existing callers to use the new code as we make changes.

In this episode

00:00:42 Review the benchmark method
00:01:37 Change the method to a function by taking or returning field values
00:01:55 IntelliJ extract parameter bug
00:03:11 IntelliJ Extract Function bug
00:04:13 And also other non-class dependencies
00:04:54 IntelliJ Inline Function bug
00:05:24 We can reorder calculations inside the function to get better timing
00:06:39 Now pull the server out of the function by extracting the bits that don't need it
00:08:32 Do the same again for the client
00:10:29 Break action dependencies with lambdas
00:10:53 IntelliJ Extract Variable bug
00:11:58 Now we can use generics to break the last dependency
00:12:56 Change the names to be more generic
00:13:50 Reorder for sense
00:13:58 Make our final option a strategy lambda
00:15:24 Finally we can do better for our synchronised collection

This video is in a playlist of Ktor episodes (   • Ktor  ) and http4k (   • http4k  )

If you like this, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook (http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.


Смотрите видео Generalising all the things - Expert Kotlin Refactoring онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 10 Май 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 634 раз и оно понравилось 39 людям.