Formatter Objects: Testable Fragments

Let’s face it — Fragments are a pain to test and it’s predominantly due to how the Android operating system works. Sometimes, you’ll find yourself writing business rules regarding how a view is displayed. Likely, some data will come back from a web server and you’ll have to format some text differently or color something differently. Nothing crazy, but all this code adds up and needs to be tested. Ideally, you’ll have some form of automation coverage to help tackle this problem, but Espresso tests can be slow and environment dependent. But what If I told you that you could...

What you need to know about the Gilded Rose interview problem

A few years ago, I interviewed for a Dev Ops position at a pretty prominent CI shop in San Francisco. Part of the interview process involved a take-home code-assignment (of course). This particular assignment is known as the Gilded Rose. The Gilded Rose isn’t a fizzbuzz. It’s not “Implement a Trie” in whatever language you want. The Gilded Rose is a problem that involves adding some functionality into the worst code that a developer could ever write. I don’t mean any offense to whoever created the Gilded Rose problem, bad code is entirely the intention! They want to see how...

The Facade Pattern for Simple Dependency Injection

I’ve been working on a Ktor api for a while now and found myself needing to make sure my routes had access to my repositories. Naturally, I sought out the advice of anyone who’s implemented Dagger with Ktor. After digging for a bit, I realized that it was completely unnecessary and likely overkill. Dagger works great on Android because you are tied to the constraints of the platform and lifecycles, but with Ktor I have control of the entire scope of my application. So I considered trying Koin. I hadn’t used it yet but have heard people recommending it over...

Controllers in Ktor

Ktor is a microframework written in Kotlin. It’s focus is on building asynchronous servers and clients in connected systems. I’ve been using it predominantly for the “server” slice of that statement. I call Ktor a “microframework” simply because, while it’s opinionated, you have a lot of freedom in the way that you accomplish tasks within the framework. If you’d like to follow along, you can scaffold out a basic Ktor project via Intellij Idea or the online tool for generating a seed project. The main idea behind the Ktor server is that everything is contained within an application and you...

Lambda-Map Performance in Kotlin

Working on an enterprise application written in Kotlin, I’ve recently noticed something that felt “off” to me. Perhaps you’ve seen it, perhaps you’ve written it — maybe even recently!  It looks something like this (I call this a Lambda-Map): object Demo { fun main() { listOf(1,2,3,4).map { plusOne(it) } } private fun plusOne(i: Int): Int = i + 1 } Sure, this plusOne function isn’t really necessary. We can just inline it in the Lambda, but imagine for just a moment that this function does much, much more than just add one to a number. It then feels just to have...

Introducing KotlinToday.com

When I was learning Clojure for the first time, I had two references that I found myself reading every single day. The first resource is a fantastic guide by Daniel Higginbotham called Clojure for the Brave and True. The second resource that I found myself using allowed me to immerse myself into the Clojure community and figure out where people were focusing their efforts – Planet Clojure. Planet Clojure is a metablog that pulls in blog posts from a vetted list of Clojure developers. In fact, you may have even seen some of my posts on there, too! Unfortunately, when I...

Sequence – A Kotlin Type

Kotlin, despite being an object oriented language, offers a ton of support for Functional paradigms. One of the most common functional paradigms involves using a combination of map, filter, and reduce on Iterable types. However, Kotlin uses extension functions on Java Collections to create these functions in their standard library. That means that when you call map on a list, you’ll return a new list. This is usually intended, however, it can become problematic when chaining multiple operations on the same list — You’ll create a ton of intermediate lists! Sequences provide a clear and performant alternative to multiple intermediate lists. Sequences...