This one’s important - Refactoring to Functional Kotlin

preview_player
Показать описание
I know - I said that there would only be one FizzBuzz episode! But then people kept making comments on that episode, and asking me questions, and HTTP benchmarking is still hard, and I just can’t help myself, I like to play with code and talk about it.

So today we’ll go back to a blank FizzBuzz slate and use the exercise to look at a really important topic - actions and calculations, or impure and pure functions. We’ll get things working as quickly and dirtily as we can, and then look at the code to help understand the difference between the function types: why we should prefer calculations; why actions come to dominate our code unless we take, erm action; and how to use Kotlin sequences to keep our code both pure and responsive.

In this episode

* 00:01:16 What is an acceptance test?
* 00:01:58 Testing one layer down from main
* 00:03:44 JFDI
* 00:04:45 What is an Action?
* 00:06:59 Why do we differentiate?
* 00:07:19 Splitting actions from calculations
* 00:08:55 Actions begat actions
* 00:09:27 Functional programming hides actions
* 00:10:39 Seek and destroy actions
* 00:12:07 Large results of calculations can be a problem
* 00:13:07 Getting creative with calculations
* 00:13:56 Hiding state in an iterator
* 00:16:25 Iterables and Sequences are the same really
* 00:19:06 Don't look behind the curtain
* 00:19:23 Round up

Рекомендации по теме
Комментарии
Автор

Good stuff! I'm trying to learn more about sequences and this has given a lot to chew on. Love your use of the IDE to make changes quickly and safely.

codeRight
Автор

Technically the `i is being mutated` at 9:26 is an implementation detail. Kotlin could've implemented for loops over Int ranges as a tail-recursive function and instead of mutating `i`, it would instead call itself but passing a new value of i. Of course, that's inefficient (unless you use the `tailrec` modifier, which will convert it to a loop with mutation anyways)

kyay
Автор

I wish your content didnt use a white background for your IDE. It hurts my eyes to watch it. It if was in dark mode I would watch but sorry I just cant.

Kikoshi