Jordan blogs Blog

Merging multiple files into one with Kotlin

Kotlin lets us write top level functions, this enables us to write code that isn’t necessarily constrained to the concept of classes. It frees us from “util” classes of static methods (but it doesn’t free us from dumping methods or functions in one place). Under the hood, Kotlin is constrained to classes, the compiler must generate bytecode that will run in the JVM (multiplatform is another story). To do this, it must put your functions into a class. It will take your file name and create a class from it. Functions in StringExtensions.kt will be placed in a class named StringExtensionsKt....

Experimenting in a legacy code base

Experimenting in a legacy code base

I work on what could be called a “legacy code base”. We’ve just crossed the 10 year anniversary of the first commit. Between then and now over 40 developers have contributed. Many features have come and gone, and the platform we develop for has changed beyond recognition and so have our ways of writing code. Because of these reasons, we have a vibrant, frustrating, yet interesting code base. Over the past three or so years we have systematically refactored and improved it, but we have a lot further to go. We’re in a place where we can start to think...

To abstract or not to abstract

To abstract or not to abstract

The longer I’ve written software the more I debate with myself about whether I should be adding an abstraction or not adding an abstraction. Let us define an abstraction, it could be an interface, a trait, a protocol, or an abstract class. It is a structure that defines how a piece of code should interact with the outside. But not how that interaction is handled. Abstractions are a powerful tool, but they should be used appropriately. They are powerful at the boundaries of your code but introduce too much indirection when used overzealously. A good abstraction lets a developer switch...

Some thoughts on testing

Some thoughts on testing

I associate a number of things with writing test code. The first is finding peace of mind. In years gone by I have written some dodgy code that has gone to production, I still think about some of this code to this day. I still write dodgy code, but I’m able to stop it from going to production with a superpower I have gained. That superpower is to write tests for my code and mostly stop that code from being released (crashlytics will sometimes disagree). A good set of tests should be enough to give me confidence that what I...

Slice don’t Splice

Slice don’t Splice

This weekend I’ve spent some time working on a side project written TypeScript, I’ve never used it before so I’ve spent a lot of time referring to documentation and learning a lot. One thing stood out. I had an array of data that I wanted to create a sub-list of elements starting from and index, i, to a range. You can do this by calling array.slice: “Extracts a section of the array and returns the new array” https://www.tutorialsteacher.com/typescript/typescript-array Typescript, or the underlying Javascript also has a function that adds or removes elements from an array. This is called array.splice: Adds...

Some thoughts on use cases in Kotlin

Some thoughts on use cases in Kotlin

Originally published here on Medium: https://medium.com/@jordanfterry/some-thoughts-on-use-cases-in-kotlin-6ac8021cbcf1 Recently at the Guardian we’ve started to apply the use case pattern to our business logic. A high level overview of a use case is a class that will encapsulate a particular piece of business logic, or behaviour in your app. You may know of this as an interactor pattern as advocated for by Robert Martin in Clean Architecture. They are easy to interpret and test, which will in turn increase both developer productivity and confidence in the quality of a team’s code. I like to call our use cases “functional use cases”? Why?...

January 2019 in sports

January 2019 in sports

As the year counter ticked over from 2018 to to 2019 I kicked into motion my plan to get better at this sports thing. This mainly took the shape of doing a lot more exercise and trying to stick to my training plan as closely as I can. Here’s some numbers from Training Peaks: Total time – 40 hours 29 minutesTotal distance – 726km Running time – 9 hours 40 minutesRunning distance – 93.4km Cycling time – 20 hours 6 minutesCycling distance – 620km Swim time – 4 hours 37 minutesSwim distance – 11,845m Strength time – 3 hours 15...

The Great South Run 2018

Between my Sister, Dad and Mum the Terry family have completed The Great South Run a total of six times. Every year a family member has completed it I have never found myself quite ever wanting to run the 10 miles (16km) around Portsmouth. However, given my new found love for endurance sport I thought this year would be as good a year as any to give it a go. I can tell you already that having done a few sprint triathlons, some long bike rides and few casual training runs does not translate to a very pleasant 10 mile...

Wind, snow and more snow

Once again I have been defeated by the weather an another attempt to complete my qualifying cross country. My first attempt on Wednesday was scuppered by forecast strong and gusty winds – that was a hard one to cancel as the sky was clear and the winds were calm. Luckily, the winds did get quite gusty which I think proved my decision right! The second chance will be tomorrow, but as the UK is currently being battered by negative temperatures and snow from the beast from the east I think it will be very unlikely. I think I will hold...