This is a short response to the recently announced Go 2 generics draft proposals Update: This proposal is incomplete. It cannot replace two common use cases. The first is ensuring that several formal parameters are of the same type: contract comparable(t T) { t > t}func max(type T comparable)(a, b T) T Here a, and […]
#generics
9 posts
3 Sept 2018
29 May 2018
This post discusses how maps are implemented in Go. It is based on a presentation I gave at the GoCon Spring 2018 conference in Tokyo, Japan. What is a map function? To understand how a map works, let’s first talk about the idea of the map function. A map function maps one value to another. Given […]
1 Nov 2017
If you want to make Swift programmer shudder, just whisper the words “associated types.” They’re one of the few Swift language typing features you’re unlikely to find in other programming languages, so they can take some getting used to. Last week I tried to write a seemingly simple function, and ended up spending most of my day diving down the…
22 Jul 2017
A long time ago, someone–I normally attribute this to David Symonds, but I can’t be sure he was the first to say it–said that the reason for adding generics to Go would be the reason for calling it Go 2.0. That is to say, adding generics to the language would be half baked if they […]
18 Jun 2017
In my previous post I discussed my concerns the additional complexity adding generics or immutability would bring to a future Go 2.0. As it was an opinion piece, I tried to keep it around 500 words. This post is an exploration of the most important (and possibly overlooked) point of that post. Indeed, the addition of […]
14 Jun 2017
Fifteen years ago Python’s GIL wasn’t a big issue. Concurrency was something dismissed as probably unnecessary. What people really was needed was a faster interpreter, after all, who had more than one CPU? But, slowly, as the requirement for concurrency increased, the problems with the GIL increased. By the time this decade rolled around, Node.js and […]
21 Apr 2016
A very interesting question was posted to Stack Overflow and reddit just recently about Java generics. Consider the following method: While the unsafe cast seems a bit wonky, and you might guess there’s something wrong here, you can still go ahead and compile the following assignment in Java 8: This is obviously wrong, because Integer … Continue reading The Parameterless…
16 Feb 2016
Before I move on with the actual article, I’d like to give credit to Daniel Dietrich, author of the awesome vavr library, who has had the idea before me: @lukaseder try with a static method <T, T1 extends T, … Tn extends T> Seq<T> toSeq(T1 t1, …, Tn tn) { … } (from my mobile … Continue reading An Ingenious…
30 Apr 2015
I admit, we’ve been lured into using this technique as well. It’s just so convenient, as it allows for avoiding a seemingly unnecessary cast. It’s the following technique here: Now you can type safely assign anything from the wrapper to any type: This is actually the API you can use when you’re using jOOR, our … Continue reading This Common…