To me, coding feels more like gardening than building. Instead of erecting permanent structures, we are planting things that grow, and occasionally die.
Sometimes we need to move code from one place to another where it is better suited. Sometimes a class is alive but just cluttering things up. If so, then we can dig it out and spend the time that we would have spent weeding and feeding on more productive tasks.
Today then we’re going to remove code from our Gilded Rose codebase, leaving it with the same features for our customers, but easier to work with for developers.
In this episode
00:00:36 We are currently loading stock data from a TSV file
00:01:22 and from Postgres
00:02:25 The unnecessary code is a bit of a burden
00:03:20 Remove DualItems from the production code
00:04:29 Now remove its tests
00:05:57 We had a test to remind us that we had some work to do when DualItems is obsolete!
00:06:45 Now we can delete that test and the DualItems
00:07:51 Remove StockFileItems test-first
00:08:47 and its configuration
00:09:19 Review and commit
00:10:24 Can we tidy up DbItems now that we are in the area?
00:10:49 IntelliJ inline is really broken
00:11:55 Undo when things get too bad and try another tack
00:13:19 Are we doing enough in the database?
00:13:42 We get a warning either way we call isEmpty!
00:14:16 Manually test because we don't have acceptance test coverage
There is a playlist of TDD Gilded Rose episodes - • Test Driven Gilded Rose in Kotlin
The codebase is available on GitHub https://github.com/dmcg/gilded-rose-tdd
If you are going to be at KotlinConf 2025, or even just in Copenhagen in May, then you should totally be signing up for the workshop that Nat Pryce and I are running. It’s called Refactoring to Functional Kotlin, and will give you hands-on experience of taking legacy code and safely migrating it to a functional style. Places are limited, so buy now at https://kotlinconf.com/workhops
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
Смотрите видео Tidy First Kotlin - Removing Redundant Code онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Pairing with Duncan 22 Ноябрь 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 568 раз и оно понравилось 36 людям.