The Bowling Score Kata in (mainly) Functional Kotlin

I don’t often have a title in mind when I record these videos – I just write code and then look for an emerging theme while I’m editing – preferably one that will interest you enough to click through and watch until the end.

Having completed this, the 4th part of our 10 pin bowling simulator, I’m still not sure what the theme is. You should totally watch it though, and then let me know what you learned in the comments.

In this episode

  • 00:00:37 I’ve made the tests easier to read
  • 00:01:18 Start modifying our tests to include the score
  • 00:01:38 I think that we got our domain model wrong with the Score being part of Frame
  • 00:02:41 Make some space for new code
  • 00:03:12 Mutating a var in a map! Horror!
  • 00:03:45 Split rendering the score from rendering the frame
  • 00:05:38 Now we can use our types
  • 00:06:57 Discovering new operations on our existing types
  • 00:09:42 Implement totalPinCount as a method
  • 00:11:04 Re-enable tests now they have a hope of passing
  • 00:13:46 Now raise the bar with strikes
  • 00:14:32 Always strive to keep tests as simple as possible
  • 00:16:50 Now spares
  • 00:18:48 Scoring makes us re-evaluate our basic model again
  • 00:21:28 Sometimes we get lucky and tests break
  • 00:22:22 Commit
  • 00:22:33 Wrap up

You can see the code on GitHub https://github.com/dmcg/bowling-for-youtube and this miniseries in a playlist https://www.youtube.com/playlist?list=PL1ssMPpyqocjSQbAigPgMpDzLMxMc7kSv

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.

submitted by /u/dmcg
[link] [comments]