1. Learn Go, 2. Make Go code faster, 3. Extend Go • The Applied Go Weekly Newsletter 2024-03-23
Your weekly source of Go news, tips, and projects
In earlier issues of this newlsetter (like this one), I mentioned Codapi.org, a universal, embeddable code playground. Recently, Codapi author Anton Zhiyanov added a growing list of "Try X in Y minutes" pages, which are executable versions of the famous "Learn X in Y minutes" pages. I am happy to contribute "Try Go in Y minutes" to this list! As of this writing, it is still a work in progress, but I am almost finished, so if you read this, you might already be able to try Go interactively. If not, the articles in this issue might help you kill time until then (and learn something new, of course!)
Learning Go in 2024; From Beginner to Senior
Not sure where to start learning Go, or what to learn next? Matt Boyle did the tedious work for you and curated an extensive list of learning resources for new, intermediate, and advanced Gophers.
Learning Go in 2024; From Beginner to Senior
One Billion Row Challenge in Golang - From 95s to 1.96s
The one billion row challenge continues! This time it's Renato Pereira who accepted the challenge and got his code faster by an order of magnitude. The biggest performance increase was the first one when going from single-threaded to concurrent processing.
One Billion Row Challenge in Golang - From 95s to 1.96s
Go Enums Still Suck
Steven loves rage bait titles. But don't let the title of his new article befog your mind. Four weeks after his first article about why Go enums suck are not optimal (simply because enums do not exist at all in Go), he took the feedback on that article to vastly improve his enum package. Here are the results.
Podcast corner
Cup o' Go
Do you know Elvish, the shell with an integrated scripting language so powerful like there's no POSIX? After this episode, you will know it.
Cup o' Go | 🚫 Computer says "No" 🧝 Plus one shell to rule them all with xiaq
Go Time
When you were new to Go, what questions crossed your mind? I bet there were a lot! Duarte O.Carmo shares some insights from his early Gopher days.
Questions from a new Go developer (Go Time #308)
go podcast()
John Arundel, Go mentor and author of a number of Go books, like "For the love of Go", talks with host Dominic St-Pierre about cryptography and his new book.
go podcast() | 032: Go cryptography with John Arundel
Go Tip of the week: Risor
If you want to make a Go binary extensible at runtime, a scripting language can be a good choice. But which one to choose?
I plan to explore a few Go-embeddable scripting languages, and today I take a look at Risor. Here is a mini-portrait of this language.
Risor is a language of its own. It is not a dialect of some well-known scripting language, which might not seem like an advantage, because this means there is new syntax and semantics to learn.
Fortunately, Risor aims at being easy to learn for everyone who knows either Go or Python. Here is a simple Risor function that returns the last element of a list:
func last(data) {
if len(data) == 0 {
return nil
}
return data[-1]
}
Other language aspects are borrowed from Python, such as lists that can hold elements of multiple types. Here is a sample taken from Risor's REPL:
>>> l := ["a", 1, 2]
["a", 1, 2]
>>> l.append("tail")
["a", 1, 2, "tail"]
(Yes, Risor ships with a stand-alone interpreter and REPL command, so you can use it independenly from Go.)
Calling a Risor script from Go is quite straightforward. The Eval function invokes a Risor function that must return a single result and an error value. Input to the script is mapped to Go variables by calling WithGlobal(). This small example from the project's README calls math.sqrt()
on an input supplied by the Go program:
package main
import (
"context"
"fmt"
"log"
"github.com/risor-io/risor"
)
func main() {
ctx := context.Background()
script := "math.sqrt(input)"
result, err := risor.Eval(ctx, script, risor.WithGlobal("input", 4))
if err != nil {
log.Fatal(err)
}
fmt.Println("The square root of 4 is:", result)
}
(Try it in the Go playground.)
Risor comes with a list of builtins and a range of modules. Looking at some of the modules, I get the impression that Risor could be a great scripting language for Ops requirements. Besides "typical" modules like strings
or time
, you can find aws
, gha
(Github Actions), kubernetes
, or vault
(for Hashicorp's Vault app).
Last not least, if you want to contribute a module, you can weigh in all your Go expertise, as Risor modules are written in Go.
Bottom line: Risor is a language with a familiar look-and-feel and a high affinity to Go. It can be embedded in Go code and run stand-alone, which makes Risor a versatile language, suitable for a wide range of use cases.
I'll certainly play a bit with Risor, to see where it could turn out to be useful in my projects.
Are you using embedded scripts with Go? If so, what is your favorite scripting package?
Overheard on Mastodon
How to be a successful IT consultant:
- Enter a legacy project with tons of cruft.
- Delete lots of code you don't understand (this is crucial).
- The project still runs fine, and is now even faster than before.
- Everyone loves you and thinks you are a genius!
More articles, videos, talks
A new Go forum based on Apache Answer (Go powered). The project owner is quite modest about his creation: "There's no ads on it or anything – a community service which may or may not get used. I'd like to improve on it more."
GitHub - savendra1/clipse: A configurable TUI clipboard manager for Unix.
Browse through your shell history conveniently in a TUI app.
Statistics of user activity from the 3,000 most active subreddits. A first-time Go app from a NodeJS programmer. Cool!
GitHub - haashemi/writer: ✍️ A simple text-on-image writing package for Go
Write text to an image. That's it. Simple but useful. Its secret is that it uses HarfBuzz under the hood.
Go Generics Improvements for Maps and Slices
If you haven't had time for looking into the new
maps
andslices
packages yet, this article should help you catch up.
Generics facilitators in Go · rakyll.org
Go tips and tricks. Write Go as Redditors in
/r/golang
do!
Measuring your system’s performance using software (Go edition)
If you want to optimize for performance, knowing the underlying system's behavior (such as memory bandwidth, branch prediction, or CPU cache lines) is crucial. This (long!) article explains all the interdependencies of Go software and the hardware it runs on.
Maps of functions in Go (Golang)
Functions are first-class objects in Go, and Willem Schots makes use of this by loading a map with functions for evaluating different types of environment variables.
IBM Open Enterprise SDK for Go 1.22 (on-prem and container image) is now available!
Go... on a mainframe OS... in containers!
Clean Domain Driven Todo List in Go
With this article about Domain-Driven Go, Mohamed Alnashmi started a mini series on Go programming. Next up is BDD in Go.
Projects
Libraries
GitHub - gen2brain/avif: AVIF image encoder/decoder
An interesting approach: "All libraries will first try to use a dynamic/shared library (if installed) via
purego
and will fall back to slowerwasm
implementation. "
From GoTH to GoTHT (or GoTTH): Go, Templ, HTMX, and Tailwind CSS as the basis for your next web app, perhaps?
GitHub - donseba/expronaut: An adventurous exploration of expressions in Golang
Author: "Expronaut is an expression parser that goes beyond the ordinary, offering the flexibility to incorporate additional methods for parsing even more complex equations."
GitHub - will-lol/numberconverter: Convert between English numbers and Integers in Go!
There may be one reason or three hundred thousand and fifty-seven reasons to convert a number between numeric and "prosaic" representation.
pgx
, a popular PostgreSQL driver, provides convenience functions for parsing values from rows.pgx-collect
does the same but faster.
Tools and applications
GitHub - yusufcanb/tlm: Local CLI Copilot, powered by CodeLLaMa. 💻🦙
An AI assistant in your terminal that does not require access to hosted LLMs. (But note that locally running LLMs require some decent amount of RAM. From a quick search, I couldn't determine how much exactly, but I'd assume that 16 or 32 GB wouldn't go astray.
Test coverage is overrated. But ignoring it completely is not wise either! So check it at least for PRs. This GitHub action does this without external dependencies.
GitHub - Malwarize/retro: 📼 play musics with command line
If a full TUI app is too much, try this command-oriented music player.
cloudzip
takes advantage of the HTTP range functionality for downloading only a part of a ZIP file and the fact that ZIP files have a central index.
Completely unrelated to Go
A well-designed diagram schema can express a wealth of information with a minimal set of element types. The C4 model is a great example. With only four core elements — user, internal system, external system, data store — and a 4-level hierarchy, C4 can visualize a software architecture from the broad context over containers and components to individual code entities. Here is a 4-minute overview.
Alex Pliutau | Software Architecture Diagrams using the C4 model
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.
Christoph Berger IT Products and Services
Dachauer Straße 29
Bergkirchen
Germany