Evolving backwards • The Applied Go Weekly Newsletter 2024-06-16
Your weekly source of Go news, tips, and projects
The world is constantly evolving, no doubt! The question, however, is: in which direction? Mostly towards increasing complexity (see also last week's issue). Sometimes also backwards.
Web development, for example, has evolved from serving static pages to single-page applications—and back. Well, back is not the right word. We still have some tricks up the sleeve that the 2000s did not have, such as server-side events.
Programming languages are prone to evolving into mind-bogglingly complex behemoths over time. Go is a positive exception. During more than one and a half decades, Go managed to grow its number of features as slowly as (probably) no other language did, at least no other language that is still in wide use. Still, Go did not stand still. Generics in Go 1.18 or iterators in Go 1.23 are examples of complexity creeping in.
Whenever systems evolve towards complexity, there are two ways of dealing with it: Simplify the system again, or build tools to manage the complexity. If, for example, your project's dependencies grow to a scale where only a 3D dependency graph would help shed light into the dependency jungle, then—well—, use a 3D dependency graph tool.
I have no particular conclusion to draw, but you're invited to read the featured articles (and project) that take the above topics further.
Have a great Go week!
Live website updates with Go, SSE, and htmx
How Miłosz Smółka uses Go, HTMX, and Watermill to implement server-side events for pushing updates to browsers.
Live website updates with Go, SSE, and htmx
Go evolves in the wrong direction
Do recent and upcoming language complications additions add enough benefit to justify the increasing language complexity? Aliaksandr Valialkin says no. Generics are still barely adopted, and the range operator just adds one more way of iterating to the many iterators the standard library already has, while complicating the language's semantics.
Go evolves in the wrong direction | by Aliaksandr Valialkin | Jun, 2024 | Medium
gabotechs/dep-tree
Project of the week: Does your project become too complex? Do you lose track of the dependencies? Display it as an interactive 3D dependency graph! The best part: The tool works with Go, Rust, Python, JavaScript, and TypeScript.
Podcast corner
Go Time: How things get done on the Go Team with Cameron Balahan, Sameer Ajmani & Russ Cox (Go Time #318)
Who is better to talk about Go than the Go team? Cameron Balahan, Sameer Ajmani & Russ Cox from the Go Team are this Go Time episode's guests. Get some valueable takeaways from this show, including the insight that nil
pointer bugs are among the easiest to debug.
Cup o' Go: 🎮 Gaby, help me learn 5 tips about Game Development in Go and goreleaser them
Shay and Jonathan talk about GopherCon EU, tools for developer-level applications, why Go is (not) used for game dev, gabyhelp
the new bot in the Go issue tracker, and more.
Go tip of the week: GNU-style flags—almost
Go's flag package is often criticized for only having single-dash flags. The well-established GNU-style flags distinguish between long flag names that start with two dashes and single-letter flags starting with a single dash, such as:
grep -f <file> ...
grep --file=<file> ...
Go apps, on the other hand, would have flags like so:
go build -race .
But this is only half the truth. Go's standard flag
package actually knows double-dash flags and allows defining a flag and a shorthand version (like the --file
and -f
examples above).
First, the flag
package is agnostic about whether you prepend one or two dashes to a flag. All of these variants would be valid:
go build -race .
go build --race .
go build -a .
go build --a .
Second, you can map two flags to the same variable, to create a flag/shorthand pair. In the following code, both --bugfix
and -b
set the same variable, bugfix
, to true
.
var bugfix bool
flag.BoolVar(&bugfix, "bugfix", false, "Fix all bugs")
flag.BoolVar(&bugfix, "b", false, "Fix all bugs (shorthand)")
flag.Parse()
not := ""
if !bugfix {
not = "won't "
}
fmt.Printf("I %sfix your bugs.\n", not)
Since you can use one or two dashes as you wish, the usage is not exactly following the GNU rules:
> go run .
I won't fix your bugs.
> go run . -b
I fix your bugs.
> go run . -bugfix
I fix your bugs.
> go run . --bugfix
I fix your bugs.
> go run . --b
I fix your bugs.
So this is almost, but not quite, GNU-ish. Furthermore, you cannot put multiple single-character flags behind the same dash, such as -abc
instead of -a -b -c
. For this level of compatibility, you can revert to third-party packages like github.com/spf13/pflag.
Quote of the week: Good at fixing problems
Humans are good at fixing problems mostly because we are good at making them.
More articles, videos, talks
Distributed File Storage In Go – Full Course - YouTube
Bring 10 hours of time and a sufficiently large monitor (smartphone won't do) to this marathon coding video by AnthonyGG.
An Applied Introduction to eBPF with Go — Ozan Sazak
eBPF lets user-space apps trace system calls, user space functions, library functions, network packets, and more. Ozan Sazak explains how to use ePBF in a Go app.
Putting Go's Context package into context
Everything needs to be put in context, even the context
package. Abin Simon wrote a primer for concurrency starters.
Build a complete REST API for a Kanban App from scratch | Learn Go / Golang, Postgres, and Postman - YouTube
2:40 hours of REST! (Pun just happened.)
Ep. 5: Efficient Concurrency in Go: Managing GoRoutines and Load Shedding
Bill Kennedy on Goroutine management, with a focus on avoiding orphan goroutines and achieving clean shutdowns.
Projects
Libraries
GitHub - meyermarcel/annot: Annotate a string line with arrows leading to a description.
Say you want to print out a string in the terminal and explain parts of this string by adding pointers with annotations below the string. Like, for example, you write a compiler that shall explain why a particular line of code fails to compile. annot
does exactly that.
GitHub - thejerf/mtmap: Type safe multi-type map for Go
Like map[any]any
but with type safety. If you add an int
value to the map, the associated key returns the value as an int
,
GitHub - EvilBytecode/GoDefender: Anti Virtulization, Anti Debugging, AntiVM, Anti Virtual Machine, Anti Debug, Anti Sandboxie, Anti Sandbox, VM Detect package.
This package sparked a hilarious discussion on Reddit:
"Malware framework? Asking for a friend"
"looks like it yeah. Its either for malware or non-open source programs."
"What's the difference?"
(To the defense of GoDefender (pun happened, again), the author claims to be in a "purple team", that is, a security team that runs attacks on systems to analyze the security measures. So at least, they're not official black hats.)
GitHub - jreisinger/checkip: Get (security) info about IP addresses
Discover various security-relevant information about an IP address, including DNS names, location, TLS certificate information, and whether it's a server on AWS.
GitHub - MhmoudGit/html2pdf: A wrapper around rod and pdfcpu designed specifically for converting HTML to PDF
On the command line, I'd use pandoc for that purpose. But in a Go app? This package, probably.
GitHub - Nicolas-ggd/rate-limiter: Rate Limiter middleware in Golang using the Gin based on Redis
Reduce your gin consumption! Joking aside, rate-limiter
is a middleware for Gin that works by storing request keys in Redis for a specified interval.
GitHub - browserutils/kooky: Go code to read cookies from browser cookie stores.
If your app makes web requests that need an existing browser cookie, this package helps you scrape that cookie from your browser's cookie storage.
GitHub - EvilBytecode/GoRedOps: 🦫 | GoRedOps is a repository dedicated to gathering and sharing advanced techniques and offensive malware for Red Team, with a specific focus on the Go programming language, all is made for educational purpoeses only.
For red teams and other pen testers. Gather knowledge about malware attacks to develop tailored defenses.
GitHub - jftuga/dtdiff: Golang package and command line tool to return or output the difference between date, time or duration
Conveniently calculate date diffs. Uses the Carbon time package under the hood.
Tools and applications
GitHub - meyermarcel/annot: Annotate a string line with arrows leading to a description.
Say you want to print out a string in the terminal and explain parts of this string by adding pointers with annotations below the string. Like, for example, you write a compiler that shall explain why a particular line of code fails to compile. annot
does exactly that.
GitHub - thejerf/mtmap: Type safe multi-type map for Go
Like map[any]any
but with type safety. If you add an int
value to the map, the associated key returns the value as an int
,
GitHub - EvilBytecode/GoDefender: Anti Virtulization, Anti Debugging, AntiVM, Anti Virtual Machine, Anti Debug, Anti Sandboxie, Anti Sandbox, VM Detect package.
This package sparked a hilarious discussion on Reddit:
"Malware framework? Asking for a friend"
"looks like it yeah. Its either for malware or non-open source programs."
"What's the difference?"
(To the defense of GoDefender (pun happened, again), the author claims to be in a "purple team", that is, a security team that runs attacks on systems to analyze the security measures. So at least, they're not official black hats.)
GitHub - jreisinger/checkip: Get (security) info about IP addresses
Discover various security-relevant information about an IP address, including DNS names, location, TLS certificate information, and whether it's a server on AWS.
GitHub - MhmoudGit/html2pdf: A wrapper around rod and pdfcpu designed specifically for converting HTML to PDF
On the command line, I'd use pandoc for that purpose. But in a Go app? This package, probably.
GitHub - Nicolas-ggd/rate-limiter: Rate Limiter middleware in Golang using the Gin based on Redis
Reduce your gin consumption! Joking aside, rate-limiter
is a middleware for Gin that works by storing request keys in Redis for a specified interval.
GitHub - browserutils/kooky: Go code to read cookies from browser cookie stores.
If your app makes web requests that need an existing browser cookie, this package helps you scrape that cookie from your browser's cookie storage.
GitHub - EvilBytecode/GoRedOps: 🦫 | GoRedOps is a repository dedicated to gathering and sharing advanced techniques and offensive malware for Red Team, with a specific focus on the Go programming language, all is made for educational purpoeses only.
For red teams and other pen testers. Gather knowledge about malware attacks to develop tailored defenses.
GitHub - jftuga/dtdiff: Golang package and command line tool to return or output the difference between date, time or duration
Conveniently calculate date diffs. Uses the Carbon time package under the hood.
Completely unrelated to Go
You should keep a developer’s journal
Yes, you should. Not for sentimental reasons. Think more of a Star Trek Enterprise logbook. Writing a developer's journal enables you to reflect on your work and examine what worked well and what didn't. This way, you can identify your strengths and weaknesses and become a better developer over time.
How to Build Anything Extremely Quickly
The Outline Speedrunning algorithm can help you avoid the "everything must be perfect" rabbit hole and deliver faster.
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