https://stackoverflow.com/a/498329/729738
.Net generics do have same issues mentioned in the article
51–60 of 305 posts
https://stackoverflow.com/a/498329/729738
.Net generics do have same issues mentioned in the article
I think in Java, you would need to do a type-class approach. interface Numeric { T zero(); T add(T a, T b); } static T sum(Numeric n, T[] v) { T summer = n.zero(); for (int k = 0; k
I think Go's generics are reasonable, but not quite powerful enough to scale. It's all well and good to generalize basic containers and functions (good, in fact), but I wish the language was better at inferring types. I'm sure this is something that will improve with time, but a bit after generics were released, I tried to build a type-safe language evaluator in Go using generics and found them lacking the kind of ty…
If you want a sophisticated type system with a language they complied to native code then use Swift or Rust.
I personally think it is good to have some choice in complexity level and that at least one language, Go, tries to carve out a niche in simplicity.
I am only barely convinced that generics was the right choice for Go.
The title says Go generics are not bad, and then in less than a page this guy only compared one use case with Java's generics. I'd expect a CS professor to be able to add a little more rigor in a blog post but I guess everyone is losing patience to read and write these days, even for the supposedly erudite.
This is his blog, he can write whatever he wants. It is not a peer reviewed paper or even arXiv. Someone submitted and people liked it, and it ends up in HN front page. All I am saying, please don't put pressure on random blog writers. You can criticize the content without saying "CS professor can be more rigor".
https://go101.org/generics/888-the-status-quo-of-go-custom-g...
I mean, my cousin still in high school can do better than that...
Earlier quoted context omitted.
For example, by not allowing one to create a parametrized method. `func (self SomeNonGenericType) Foo[T any](param T) T` is not allowed, best one can do is `func Foo[T any](self SomeNonGenericType, param T) T`. The reasons are explained here: https://go.googlesource.com/proposal/+/refs/heads/master/des... but the point is, you can have this in Java, but not in Go.
You can certainly use generic parameters in methods—the [T any] just has to be on SomeNonGenericType, even if it's not used inside the type itself https://rakyll.org/generics-facilititators
- func (self SomeType[T]) Foo(...) is a method for a class parametrized on T. So if you want foo.Foo(1) then it only works for foo that's SomeType[int]. You cannot then easily call foo.Foo("one") on the same instance.
- func (self SomeType) Foo[T any](...) - if that'd be a thing - would be a generic method on SomeType that works for any T. So you can foo.Foo(1) and foo.Foo("one") on the very next line and that would work.
This is like the most cherry-picked example that could've been chosen. Java can't do this because the primitive types are not objects. Mentioning the performance of this is hilarious because 1. it's Daniel Lemire, he should know better and 2. the performance of pretty much every other thing that uses generics is terrible because of gcshapes being passed everywhere and 3. Java literally has a JIT to make generics fast…
I would rather call it cherry-picking if one avoided covering such a case to make Java look good. Seems like a pretty obvious problem to me.
Handling basic number types is pretty bread and butter.
this article is hilarious: 1. go generics do this one thing 2. therefore they are good Go generics are better than no generics but they're still limited, and that frustrates me.
"not bad" is a weird bar to cross for a language that: 1. decided generics is not needed 2. went on for a decade 3. implemented a version of it that is not performance-sensitive 3.5. $$ by google