First published on


chrishutchinson.me/weeknotes/learning-c-sharp-with-a-koan-modernising-legacy-tech-ipod-classic-service-works-here-be-dragons

Learning C#, modernising legacy tech (iPod edition), and tricky service workers

Learning C#, modernising legacy tech (iPod edition), and tricky service workers

Weeknotes for week beginning 18th April 2021

Learning C# with a koan

A lot of the codebases we work with at Made Tech are in C# using .NET Core. I've only ever dabbled with C# in the context of the Unity game engine, so I spent a bit of time this week getting a bit more familiar with the syntax. Instead of throwing myself into the documentation, a colleague recommended I try a 'koan', an almost story-driven approach to learning a new language. I followed this koan, which starts simple with booleans and strings, and builds up to more complex language features, including delegates, globalisation and more.

It was an interesting way of trying out a new language and certainly gave me a good overview of the core components. My learning style really leans towards actually building something with a language to get a better understanding of it, so that's next up on my list with C# and .NET Core.

If you're interesting in trying a Koan, Made Tech host a list of them here, but you can also just search for '<language name> koan' for most languages and you should be able to find something suitable!

Modernising legacy tech – the iPod Classic edition

After a few weeks wait, all the parts I had ordered finally arrived to give my iPod Classic a new lease of life. I picked it up second hand earlier this year, but found the battery wasn't holding charge beyond a few hours, and the physical hard drive only compounded the problem. I picked up a new battery from iFixit, and an iFlash-Quad, which allowed me to swap the 160GB hard drive out with up to four Micro SD cards!

Having finally built up the courage to follow the battery replacement guide (rated 'very difficult' 😱), I was able to swap out the two parts without a hitch, and so far things are looking good ⚡️! An added bonus is that the iPod is now much lighter than before, given the weight difference between the old hard drive and the new storage board.

My plan with the iPod is to create an offline device, for when I feel I need to disconnect from the world. I'm going to fill it with B-sides, and other obscure music that typically isn't available on streaming platforms. Any recommendations? Do let me know!

Service workers, here be dragons

I fixed a bug this week, the result of a website migration that moved from a Gatsby static site to a WordPress hosted theme. The bug report was something along the lines of "Help! The website won't update for me, but it will for other people, and it's been this way for two weeks!". Some theories had been thrown around: DNS caching, CDN behaviours, amongst a few others, but having dug into the issue further it became apparent that these weren't the culprits. Some remote debugging later, on the only browser I had access to that would reliably reproduce the issue, it turned out that the old Gatsby site had been using a plugin that made it work offline, via a service worker. The new WordPress website on the other hand, didn't have one. Checking up on the documentation, it turns out service workers will hold onto the last healthy version, if the URL it was registered at now returns a 404, as it was in this scenario.

If your new worker has a non-ok status code (for example, 404), fails to parse, throws an error during execution, or rejects during install, the new worker is thrown away, but the current one remains active.

This meant any browser that had the original service worker was getting the old site, and network requests were being intercepted and served from a local cache, preventing new content from appearing.

The solution: register a new service worker at the original URL that passed all traffic through to the network, resolving the initial worker 404, and ensuring those browsers with a service worker could update it and fetch content from the origin server again. Then, we added some additional code to deregister all service workers, to prevent the odd middle-man behaviour where the service worker was intercepting all traffic just to forward it on to the network.

The lesson: if you're going to implement a service worker, be damn sure you have a good reason, and make an effort to familiarise yourself with the scenarios in which a service worker will (or won't) update!

I'm reading...

I'd picked up Cyd Harrell's A Civic Technologist's Practice Guide a few months ago once I knew I was starting at Made Tech, but hadn't got around to finishing it. I really love the way it's written, and there are some really practical tips for how to have a meaningful impact in government technology.

I usually like to have a more engineering-focused book on the go too, and I have started dipping into Mazes for Programmers this week. It's a great balance of quirky curiosity and challenging algorithms.