Having lots of fun re-upping my Kotlin skills with this year's AoC.
Here are some things I've done that I think are shareable.
1. Testing without JUnit - I'm trying to avoid using JUnit and just testing with
check(), like so:
I just discovered the check() has a lazyMessage parameter, which is nice. At some point I might cave and start using JUnit but doing this still helps me do TDD well enough.
2. Declarative/functional programming is nice!
I'm starting to settle on a problem-solving approach that's kind of "bass ackwards" but very much in line with TDD
philosophy: Start with the end in mind. I'm working on Day 4 Part 2 right now and here's what I started writing:
That's it. To get the answer, I work my way backwards and implement each of these steps, breaking each one down into smaller problems when necessary.
3. Kotlin makes it easy to create DSLs (Domain Specific Languages)
Extension functions really help for declarative/functional programming. Here's what the asCards() function ended up being:
and
ScratchCard is a data class with the
of() factory function/method as a part of its companion object. This does the heavy lifting of parsing the input.
There are a few more things I'm playing around with but this is getting long and I have to get back to solving Day 4 Part 2. I'm falling way behind with all the reflection and playing around that I'm doing, but it's fun.