Since I found The Go2 Go Playground I’ve been happily playing there a fair bit. Today, inspired by fond memories of Kotlin’s Sequence, I took about an hour and implemented my favorites. I’ve written one-off variants of many of these in Go at least a dozen times. I’m looking forward to not writing these again and again. Here’s what about an hour yielded:

Given these, running the following:

Would yield:

Pets: [{family:Dog species:Pitbull} {family:Dog species:Chow} {family:Cat species:Tabby} {family:Bird species:Parrot} {family:Dog species:Beagle}] Any dog: true AssociateBy family: map[Bird:{family:Bird species:Parrot} Cat:{family:Cat species:Tabby} Dog:{family:Dog species:Beagle}] Filter dogs: [{family:Dog species:Pitbull} {family:Dog species:Chow}…

I come from languages with generics, additionally, I have issues with the amount of boilerplate code I write in Go. So, I’ve been looking forward to Go generics with hope. I’ve had specific types of generics use cases in mind, and when I found I could play with Go’s generics at The Go2 Go Playground. I decided to see if I could solve one. For those wanting the TLDR answer: yes!

My Use Case

If you’ve used Go’s container/heap, you too might feel it’s awkward. …


I’m no prude but I’m uncomfortable with Go’s naked returns. A naked return, as covered in A Tour of Go is:

func split(sum int) (x, y int) {
x = sum * 4 / 9
y = sum - x
return
}

The return is without its expected arguments, the arguments must be derived from the function signature and the assignments in the code. A Tour of Go notes “They can harm readability in longer functions.”

No, they just harm readability, and in several ways:

  • When you see the return you are forced to look at the function signature to…

This note isn’t suggesting a pattern to follow, it’s a thought exercise. Let’s look at using a closure where we’d idiomatically use a struct.

A Fibonacci Number Sequence Generator

For this thought exercise, we will implement a Fibonacci Number sequence generator two ways, once with a struct and once with a closure. We’ll use the same approach in both to compare.

As a Structure

So here’s a simple and idiomatic implementation with a struct:

package mainimport "fmt"type Fibonacci struct {
x1, x2 int
}
func NewFibonacci() *Fibonacci {
return &Fibonacci{-1,1}
}
func (f *Fibonacci) Next() int { f.x1, f.x2 = f.x2, f.x1 + f.x2 return f.x2…

TLDR; Just Want A Go Release Tool?

Jump to Using gorelease below.

The Full Read

I’m neither a lover nor a hater when it comes to Go and its ecosystem. Generally things Go are a bit rudimentary but very open and accessible. You may have to do some work yourself, but you’ll be able to get results.

Releasing Software in General

There are simple best practices around versioning and releasing software in general, regardless of language or tool:

  • Use semantic version numbers to indicate versions.
  • Make sure the release version number is constantly branded on source and artifacts.

Do those two things and you’ve got an orderly, identifiable, reproducible product.

Releasing Software in Go

So what does Go…


Photo by ron dyar on Unsplash

This is just a self indulgent memory brought to mind by some recent Information Security discussions I’ve been in. We we talking about the lengths people will go to to circumvent processes that are too cumbersome.

My father served in the military in World War II, where, when filing a requisition form he had to submit seven (!) copies. Without photocopiers, or even carbon paper, it meant typing the long form up seven separate times. Why seven copies? Because different departments along the supply chain each wanted a copy. They realized different supply chains probably involved different numbers of departments…


The Shadow Knows…

In programming, there is a situation referred to as variable shadowing. It’s when you reuse a variable name in an inner scope that was already used in an outer scope. The new variable shadows the outer one, and changes made in the inner scope to the variable will not affect the value of the variable in the outer scope.

It’s a simple thing, a valid language feature, here’s an example of variable shadowing:

Running the above you’d see:

Number of presidents: 1

Makes sense. Now change presidents := 1 to presidents := 2 and you’ll get:


Photo by SpaceX on Unsplash

I grew up in the Space Shuttle era. With the exception of the Mars rovers, not much has caught my imagination in the space race since. Until SpaceX that is. SpaceX is impressive. Consistent innovation and driven by high aspirations. Their technology has made private commercial launches the driving force in the field. Watching their rockets land on barges at sea, and knowing they keep successfully reusing them is inspiring.

A Lot Has Changed in 60 Years: Vostok 1

Vostok 1 was launched on April 12th, 1961. It was basically a bunch of 1950s intercontinental ballistic missiles (ICBM), strapped together, with a tiny deep-sea submarine, ironically referred to as…


Photo by Markus Spiske on Unsplash

If you’re curious about our reality but not familiar with the Double-slit experiment, I think you should take the time to learn about it. It was a favorite of Richard Feynman, a personal hero of mine.

So what about this experiment made me think about the “Are we living in a simulation?” question that has been discussed by folks of late? It’s where it intersects with the Copenhagen Interpretation, which posits that it’s best to stick to the math and think in terms of probability waves rather than discrete measurables.

So you have this experiment that shows that an electron…


Photo by Rick Mason on Unsplash

Cognition

In cognitive science, you’ll come across discussions of the two modes of neural activity, focused and scattered. In focused you’re working with a relatively small set of related chunks of information, for example solving a problem. In scattered your brain is ping-ponging around seemingly unrelated pieces of information and making neural connections between them, dreaming would be one example of this.

Meditation

In meditation, you’ll come across types of meditation that are geared towards focusing your mind, and those that specifically strive to unfocus your mind. This isn’t coincidental, the meditation is targeting one or the other cognitive state.

Coding From Home

Today I…

nwillc

Graybeard code monkey, started on an Apple IIe, got a CS degree in the 80’s, and coded my way through C, C++, Objective-C, Java, Kotlin — and now Go.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store