The Applied Go Weekly Newsletter logo

The Applied Go Weekly Newsletter

Subscribe
Archives
March 10, 2024

Dysfunctional options and stupid programmers • The Applied Go Weekly Newsletter 2024-03-10

AppliedGoNewsletterHeader640.png

Your weekly source of Go news, tips, and projects

Go's intricacies know no bounds - from interface smuggling that augments implementations to the surprising impact of pre-allocating slices. But amid the technical depths, a programmer's musings on embracing simplicity over engineering complexities strike a resonant chord.

Sorry. Really sorry 'bout that. I promise I won't let an AI write the intro to this newsletter again.

Dysfunctional options pattern in Go

If the common Functional Options pattern appears too convoluted, Redovan Donowan presents a simpler alternative. Ensure to also read his earlier article on configuring options in Go.

Dysfunctional options pattern in Go | Redowan's Reflections

The Impact of Pre-allocating Slice Memory on Performance in Golang

Without looking, how large must a slice be for preallocation to become effective? Surprisingly small.

The Impact of Pre-allocating Slice Memory on Performance in Golang | Oilbeater's Study Room

A tale of Interface Smuggling in Go net/http

Interface smuggling, the new "BlackHatDevs" activity in Go? No, interface smuggling is rather a way of augmenting the implementation of an interface with additional interfaces where appropriate. Mahesh Hegde explains the pattern on a real-life example.

A tale of Interface Smuggling in Go net/http

I'm a programmer and I'm stupid

Anton Zhiyanov thinks he is a stupid programmer, although his cool projects like codapi prove him wrong. But if you read between the lines, his insights about producing "stupid" code are actually a manifest against over-engineering. And some of you will have one or more "me too" moments while reading this article. (I had.)

KISS — Keep It Simple, Stupid.

I'm a programmer and I'm stupid

Podcast corner

Cup o' Go

Jonathan and Nehmad tend to release their episodes around the time I finish editing my new newsletter episode. So if you read this, the latest episode was not released before this issue went to press, but you can check the status on the Cup o' Go homepage.

Go Time

Kent Quirk, Sharon DiOrio, Steven Pyle, and Johnny Boursiquot discuss the odds of being replaced by AI.

In the end, only an AI can predict whether that will happen — but after all, who knows it if only hallucinates (once again).

How long until I lose my job to AI? (Go Time #306)

go podcast()

Chris Shepherd, Senior Systems Engineer at Cloudflare, is the guest of this episode, where he and Dominic St-Pierre talk about gRPC and other things.

go podcast() | 030: gRPC in Go with Chris Shepherd

Go tip of the week: Containers from scratch?

The typical Go binary is static and self-contained. It has absolutely no dependencies on system libraries or pre-installed runtimes.

A Go binary is therefore an ideal basis for creating super-small containers. There is no need to put a complete Linux distribution underneath a Go app. If you take it to the extreme, you can create a Go container FROM scratch.

But is this a good idea?

On a second glance, a container built from the scratch image (literally a zero-size, zero-content "image") has a number of deficiencies.

  • No user management. A Go binary in a scratch container lives in a user-free world. Calling os/user.Current() panics in a scratch container.
  • Missing system folders. An app might assume to find usual paths in their usual places; for example, /tmp or $HOME. A scratch image does not set up any paths or directories.
  • No auxiliary apps. A Go app may want to run auxiliary tools via os.Exec() that are missing from a scratch image.
  • No CA certificates. If you are serious about running a web server, you need TLS certificates. Certificates are signed by a chain of issuer certificates, up to root certificates from a certificate authority (CA). None of these exist in a scratch image.

This list is not exhaustive; there may be more obstacles depending on the app's needs.

So while Go binaries work well on scratch images in theory, the lack of basic features can be prohibitive.

Options to resolve this:

1. Work around the limits

Most of the limitations can be worked around; for example, by adding CA certificates or required directories and files to the image.

2. Use a "distroless" image

Distroless is a set of container images that are trimmed down to the barest minimum possible. The smallest version, the static image, is about 2MB in size and is made for statically linked binaries like Go binaries. The base image adds commonly used shared libaries like libc or openssl.

3. Use small images like Alpine

Alpine is a Linux distribution with a small footprint (about 8MB as a container image) that ships most of the things you would expect from a Linux distro: file system, user management, system libraries, packet management, and more.

Bottom line: Unless the space requirements are super strict, even a Go binary benefits from container images that are more than just the scratch image.

Quote of the week: Every single codebase looks like the last one

As you use Go more and more, you will start to perhaps pine for features other languages have. I wish Go had x, I wish Go had y. But eventually, you will realise you love Go, precisely because it does not have those features.

If you’ve ever worked in a large JS project, a language with every feature imaginable, everyone will use different sets of features, no two areas of the codebase will look the same. When you go from job, to job, to job, that all use Go, and every single codebase more or less looks like the last one.

Ewan Valentine | Advice for new Go Programmers

More articles, videos, talks

Composable HTTP Handlers using generics in Go/Golang

...and you can play around, too, as the article contains runnable examples. – By Willem Schots

Ewan Valentine | Advice for new Go Programmers

If you are a seasoned Gopher already, you might still want to read that article as a refresher. Do you agree with the points made there?

When Kubernetes and Go don't work well together

TL;DR: Kubernetes sets memory limits that Go does not neccessarily acknowledges. – By Emin Laletovic.

The Impact of Preallocating Slice Memory in Golang (Continued) | Oilbeater's Study Room

Ooo, there is a second part!

Expressing creativity through code

Do you have difficulties wrapping your brains around contexts? A mental model may help. Victor Conner shares his mental model with the world, to ease the brain-wrapping.

fzf, Cheat,yeetgif,gorched,Nap,NTrace-Core, | Level Up Coding

Which of these do you know already?

Projects

Libraries

GitHub - barkimedes/go-deepcopy: A Golang package for doing a deep copy for (just about) anything

The first cut copy is the deepest.

GitHub - nikolastojkov/skopsgo: An opinionated, barebones Go starter kit using Gin, HTMX, Tailwind, and Templ.

The combination of Go, Templ, and HTMX (a.k.a GoTH) appears to become more and more popular. Here is a starter template that also includes Gin and Tailwind CSS.

GitHub - orsinium-labs/tinytest: ✅ The only assertion library that works with TinyGo

If you write code for TinyGo and stdlib isn't your cup of tea for writing test assertions, you may have found out that most assertion libraries use reflection and thus aren't a good fit for TinyGo. This one reflects nothing.

GitHub - FelixEnescu/date-range: A powerful and intuitive Go package designed for handling date intervals efficiently and effectively. This library simplifies operations such as comparing dates, checking overlaps, and processing date ranges in Go applications

Your next restautant table booking app will be a breeze to write with daterange, a package that does tedious and error-prone date range calculations for you.

GitHub - moroz/uuidv7-go

UUIDv7 includes a time-ordered value field. The IETF says, "Implementations SHOULD utilize UUID version 7 over UUID version 1 and 6 if possible."

GitHub - yassinebenaid/godump: Go library to dump variables and data structures.

If you like davecgh/go-spew, you will love this one.

goqite

Who says databases aren't good for building message queues!

Tools and applications

GitHub - thewh1teagle/Lens: Your lens to insights.

Lilke a pocket Grafana, for visualizing data from (currently) two data source types, SQLite and URLs.

GitHub - PeronGH/cli2ssh: Turn any CLI program into a SSH server

Serve CLI and TUI apps to remote machines.

GitHub - nevalang/neva: 🌊 Flow-based programming language with static types and implicit parallelism. Compiles to native code and Go

How about exploring a different programming pagadigm? Nevalang is a flow-based language that compiles to Go.

GitHub - spcbfr/ascii-go: A script that converts images to ascii art

If you want to print your images using a 1980s' line printer, look no further.

GitHub - vinceanalytics/vince: vince is a High Performance , API only , distributed, in-memory alternative to Google Analytics

API-only means Bring Your Own UI.

GitHub - rednafi/fork-sweeper: Remove unused GitHub forks

Do you have too many old repo forks around? Sweep them away with `fork-sweeper´.

GitHub - chamanbravo/upstat: a simple open-source, self-hosted status monitoring tool

Monitor HTTP server uptime and latency

GitHub - digitalghost-dev/pl-cli: A CLI tool for displaying data related to the English Premier League.

(Not) only for English Premier League fans.

holycowbatmann

A Go-powered Asteroid-like browser game!

Completely unrelated to Go

Are you doing Agile right? ARE YOU?

Slow stable releases or fast unstable releases? - Jonathan Hall

Happy coding! ʕ◔ϖ◔ʔ

Questions or feedback? Drop me a line. I'd love to hear from you.

Best from Munich, Christoph

Not a subscriber yet?

If you read this newsletter issue online, or if someone forwarded the newsletter to you, subscribe for regular updates to get every new issue earlier than the online version, and more reliable than an occasional forwarding. 

Find the subscription form at the end of this page.

How I can help

If you're looking for more useful content around Go, here are some ways I can help you become a better Gopher (or a Gopher at all):

On AppliedGo.net, I blog about Go projects, algorithms and data structures in Go, and other fun stuff.

Or visit the AppliedGo.com blog and learn about language specifics, Go updates, and programming-related stuff. 

My AppliedGo YouTube channel hosts quick tip and crash course videos that help you get more productive and creative with Go.

Enroll in my Go course for developers that stands out for its intense use of animated graphics for explaining abstract concepts in an intuitive way. Numerous short and concise lectures allow you to schedule your learning flow as you like.

Check it out.


Christoph Berger IT Products and Services
Dachauer Straße 29
Bergkirchen
Germany

Don't miss what's next. Subscribe to The Applied Go Weekly Newsletter:
LinkedIn
This email brought to you by Buttondown, the easiest way to start and grow your newsletter.