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} {family:Dog species:Beagle}]
Find dog…

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…

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 Scott Graham on Unsplash

Having been on both sides of live coding interviews, most recently more on the interviewer’s side, I wanted to share some thoughts.

Knowing Your Stuff

I think to some degree most of us suffer from a bit of the imposter syndrome in interviews. We want to make sure we appear to know our stuff. There are a lot of discussions out there about how to study and prepare for technical interviews, even ones tailored to specific hiring companies. I’ve fallen into that anxiety trap myself, boning up on well know interview algorithmic questions hoping not to be caught off guard.

Here’s the thing…


Photo by Viktor Forgacs on Unsplash

I’m not a dedicated crypto investor, but I have some meager crypto holdings that periodically like to check in on. By periodically, I mean every few days or so, or if there’ market news. I specifically do not obsess over them. There are lots of ways I could track these on my phone or computer, but again I don’t want to overdo it, so ad-riddled real-time price tickers or websites just aren’t my thing. I really just wanted a “hey how’s it going” solution, so I did the code monkey thing and wrote one.

Cryptoport

Cyptoport is a tiny bit of…


Photo by Kari Shea on Unsplash

One permanent takeaway from being a teaching assistant for college computer science courses was the value of readable, idiomatic code. When you had to thoughtfully review, back to back, many similar code samples, you don’t want them to be obfuscated. That lesson has served me well professionally, coming into play during key developer tasks like pull requests and maintaining code. Upgrading code from working to readable (and, therefore maintainable), is truly worth the effort for both you and your employer.

Golang’s Basic Cleaning Products

Go has many code quality tools available, and these may already be directly incorporated into your editor or IDE, but…


Photo by Denise Jans on Unsplash

If you follow my writing, thank you, but also you’ll know I wander afield of software development from time to time…today I’m going to talk about a movie.

Women in Motion

I’m a Star Trek fan, and also interested in real-world space exploration so when I heard about Women in Motion, a documentary of Nichelle Nichols and her recruiting at NASA I had to immediately watch it.

I can’t recommend it enough. You’ll see what a truly amazing woman Nichelle is, realizing that the role of Uhura hardly merits even a mention in her many achievements. You’ll see the incredible impact her recruiting…


In working with external code I hit the following. The code provided a function for looking up a product’s price, returning the price if available and a possible error:

func Price(product string) (float64, error)

It was a simple function, and the error case was sensible, unknown product, out of stock, etc. However, I discovered that when the item was discontinued the function resulted in a panic from deep in the external code. While I’ll pursue reporting/fixing it, I needed to guard against it from my side immediately.

Go Recover Basics

Go has a mechanism for dealing with panics, it’s the function recover(). Recover…

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