Sterling has too many projects Blogging about programming, microcontrollers & electronics, 3D printing, and whatever else...
Posts with the tag Slices:

Golang Slices are Dangerous

The headline is a little bit click-bait-y, but I want to highlight one of the easily overlooked risks of using slices in Golang. First of all, there’s nothing really wrong with the way slices work. A trade-off was made. It is not necessarily the same trade-off I would make, but such is engineering.

Consider Arrays

First, let’s map what a slice is because it might not be obvious unless you’ve been writing Golang programs for a while. Let’s start by thinking about an array. In Golang, an array is a fixed string of elements of a given type. For example, we might define an array of int32 with ten elements as follows:

ยป read more