HTML Form parsing with http4k lenses

Опубликовано: 04 Август 2023
на канале: Pairing with Duncan
513
17

Last week we worked out how to parse our new items form, albeit with NullPointer exceptions to handle missing or invalid data.

The feedback I got from David Denton, one of the http4k developers, was “You know you can use the form lenses here and avoid all this bullshit?”

So this episode we’ll refactor the current code to use form lenses, and see how much bullshit we actually avoid.

Significant moments

00:00:38 We found two bugs
00:01:35 Recreate a bug in the tests
00:04:00 Fix the bug as quickly as possible
00:04:47 Refactor to make things better
00:05:36 Add some test for other things that might not work
00:06:15 They do work, so commit
00:06:27 Review our implementation and our tests
00:07:26 Refactor our tests to reveal intention
00:09:40 Refactor parsing to use lenses
00:13:21 AI Assistant comes in handy
00:15:17 IntelliJ refactoring bug
00:21:23 http4k bug
00:23:49 Use lenses to diagnose multiple failures
00:24:37 Inline and extract to refactor to better semantics
00:30:17 Raise an event for parse failures
00:31:22 Callback to Errors are Events episode
00:31:25 Creating a custom Hamkrest matcher
00:38:02 Commit
00:38:14 Review
00:38:46 Fix bug where we have two intertwingled forms
00:41:19 Review

This is part 86 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist
   • All Gilded Rose Episodes  
and the code on GitHub
https://github.com/dmcg/gilded-rose-tdd

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.