Go Slice Visualiser

I’ve been learning Go recently; it’s been fun.

An interesting aspect of Go is Slices, which are lightweight views of an array. Why these are useful and necessary makes more sense when you understand Go’s pass-by-value semantics.

Whilst playing with slices, I put together a little visualiser to help understand their behaviour (the act of building it was probably more useful than the end result).

The Slice Visualiser

This is a tool to help you get your head around how the slice operations work visually. The ten boxes below represent an array that you’re creating slices of, the input below them is your slice operation, and the black box you’ll see is the resulting slice.


// e.g. slice[0], slice[:3], slice[1:3]