Variable scopes and shadowing in Go

A lot of things in life are a matter of perspective and visibility and the same applies to variables in Go 😅. But what is a variable’s scope, how is it defined and what does it mean to shadow a variable in Go?

Let’s (very) loosely say that the scope of a variable declares where this variable is visible from ie. if we have declared a variable at the top of the file then it’s visible from within the entire code of that file.

Photo by Eneida Nieves on Pexels.com

We can go even deeper than that though and we can break this question down into Go specific terms.

Continue reading “Variable scopes and shadowing in Go”

Sorting in Go using Bubble sort

Go has its own package for handing sorting – called “sort” but in this post we are going to use the Go language to implement a sorting algorithm called Bubble sort.

Problem definition: Given a slice of integers sort them in ascending order

Bubble sort is an iterative comparison algorithm that sorts the elements by swapping them around if they are out of order. If a larger element comes before a smaller one => swap them and move on to the next position of the array.

Continue reading “Sorting in Go using Bubble sort”

String manipulation in Go

I find the way that strings have been implemented in Go to be really interesting but also a bit confusing when you are first introduced to them. Go has native UTF8 support, which flows through how the source code is written to how strings and “runes” are represented (runes is the thing that really got me by surprise but more on that later). So what does Go do differently with strings that is worth mentioning?

Continue reading “String manipulation in Go”