This one’s important - Refactoring to Functional Kotlin

Published: 09 August 2024
on channel: Pairing with Duncan
1,061
66

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

There is a playlist of FizzBuzz episodes    • FizzBuzz  

The code is on GitHub https://github.com/dmcg/FizzBuzz/tree...

I learned about actions and calculation from Eric Norman - https://ericnormand.me

I get lots of questions about the test progress bar. It was written by the inimitable @dmitrykandalov. To use it install his Liveplugin (https://plugins.jetbrains.com/plugin/...) and then this gist https://gist.github.com/dmcg/1f56ac39...

If you like this video, 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. You can read the introduction to Chapter 7 - Actions to Calculations for free https://java-to-kotlin.dev/chapter_sa...


Watch video This one’s important - Refactoring to Functional Kotlin online without registration, duration hours minute second in high quality. This video was added by user Pairing with Duncan 09 August 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 1,061 once and liked it 66 people.