How to Write Insertion Sort in Go

insert

Insertion sort builds a final sorted list one item at a time. It’s much less efficient on large lists than more advanced algorithms like quicksort or merge sort. Insertion sort is a simple algorithm that works just like you would arrange playing cards in your hands. A slice is first split into sorted and unsorted …

Read more

Merge Sort in Golang with Examples

swirl

Merge sort is a recursive sorting algorithm and, luckily for us, it’s quite a bit faster than bubble sort. Merge sort is a divide and conquer algorithm. Divide Divide the input slice into two (equal) halves Recursively sort the two halves Conquer Merge the two halves to form a sorted array Full example of the merge sort algorithm Merge sort actually has two functions involved, the recursive mergeSort function, and the merge function. Let’s write the mergeSort() function first. It’s a recursive function, which means it calls itself, and in this case, it …

Read more

Writing Bubble Sort in Go from Scratch

bubbles in water

Bubble sort is named for the way elements “bubble up” to the top of the list. Bubble sort repeatedly steps through a slice and compares adjacent elements, swapping them if they are out of order. It continues to loop over the slice until the whole list is completely sorted. Full example of the bubble sort algorithm Using the algorithm in code Why use bubble sort? Bubble sort is famous for …

Read more

Check for Standards Before Creating a New One

flags

I recently had a ticket opened on my team’s backlog board requesting the ability to bypass our API’s caching system. For context, our front-end team uses my team’s API to make fairly heavy requests to ElasticSearch, and one of the features of our API gateway is to cache the results of heavy aggregations for ~30 …

Read more

How to Properly Use Defer in Golang

hand signal

What is the “defer” keyword in Go? In the Go programming language, defer is a keyword that allows developers to delay the execution of a function until the current functions returns. What throws some people off is that the deferred function’s arguments are evaluated immediately, but the function itself doesn’t fire until the wrapping function …

Read more

Comprehensive Guide to Dates and Times in Go

clock

Keeping track of time in code has long been a developer’s nightmare. While no language or package manages time perfectly, I’m of the opinion that Golang does a pretty good job out-of-the-box. This full tutorial is designed to answer ~90% of the questions you’ll have about managing time in Go. Table of Contents Overview – …

Read more

Continuous Deployments != Continuous Disruptions

stream running down hill continuous

Luckily, I’ve met very few engineers in my career who are outright opposed to continuous deployment. That said, I have met some, and I think their hesitation is usually rooted in the myth that continuous causes more disruptions to end-users than a batched release cycle. What is continuous deployment? Before we get into the nitty-gritty …

Read more

The 10x Meeting – Solving for Too Many Meetings

meetings on couch

Perhaps you’ve heard of the fabled 10x developer (or 10x engineer) – the one on the team that’s 10x as productive as their average colleague. While many, including myself, doubt the existence of such people, I do think there are meetings that are 10x as productive as the average meeting. My goal in this article …

Read more

Concatenating with strings.Builder Quickly in Golang

knot in string unsplash

The Go standard library makes concatenating strings easy. Concatenation is just a fancy word for adding strings together to make a larger string. For example, if we concatenate “hello”, ” ” and “world” we’d get “hello world”. The built-in fmt.Sprintf function takes a format and a variadic list of interfaces as input. The formatting option …

Read more