News for hackers. Stuff that matters.
Re:Why Go and Not Rust? by ori_b on Monday September 16, 2019 @10:55AM (#20984668)
You can implement it in Go using loops, and it's not significantly slower or more error prone.
Re:Why Go and Not Rust? by hauleth on Monday September 16, 2019 @11:02AM (#20984759)
Unless you want to implement that on top of your custom structure, like, for example, b-tree. Then you either need to write N different implementations for each separate tree or you need to use `interface{}`.
Re:Why Go and Not Rust? by ori_b on Monday September 16, 2019 @11:07AM (#20984800)
Yes, custom containers are one place that generics are very useful.

Go has the most useful containers built in. Most code I write doesn't need custom containers, even in languages with templates (I write far more C++ and Java than Go) -- so I find that I don't miss them much when I spend time in Gopherspace.

Re:Why Go and Not Rust? by NoodleIncident on Monday September 16, 2019 @01:09PM (#20986222)
The most egregious missing container is "set", coming from Python (as many Go developers do). After debugging, reviewing, and writing at least 3 different local implementations of a set, I can't wait for generics so that it can be written once and then never looked at again.
Re:Why Go and Not Rust? by mappu on Monday September 16, 2019 @04:49PM (#20988457)
I'm slightly surprised you found three different set implementations - `map[T]struct{}` is the idiomatic one i see everywhere.

I suppose it's not sorted or concurrent-safe?

Re:Why Go and Not Rust? by NoodleIncident on Monday September 16, 2019 @05:58PM (#20988984)
I mean that people make their own per-file or per-package set implementation for their service. There's no point putting it in a common utility package even within the same company, because it's specific to the type of what they're storing.

`map[T]struct{}` is only a type, it's not an implementation. You still need a handful of methods, that might be named inconsistently in each implementation by different developers. I will be happy when I never have to think about this again

Re:Why Go and Not Rust? by masklinn on Tuesday September 17, 2019 @07:37AM (#20993788)
> I'm slightly surprised you found three different set implementations - `map[T]struct{}` is the idiomatic one i see everywhere.

Set storage is not really the concern here, it's the set-theoretic operations which make sets useful (generally speaking, there are cases where all you need is the set being a set e.g. deduplication).

So I wouldn't be surprised that GP found several different implementations of union, intersection, difference, symmetric difference, subset, superset, …

Re:Why Go and Not Rust? by crimsonalucard on Monday September 16, 2019 @01:10PM (#20986230)
Yeah but you can't implement it generically.

That means for every conceivable input type and output type combination you have to have a new MAP or REDUCE function to handle it.

All Modern languages except golang and elm only require one implementation of MAP that can handle all type combinations.

It's called parametric polymorphism.

Re:Why Go and Not Rust? by excursionist on Monday September 16, 2019 @04:24PM (#20988203)
Elm has parametric polymorphism.
Re:Why Go and Not Rust? by crimsonalucard on Monday September 16, 2019 @05:18PM (#20988669)
you're right. My mistake.
Re:Why Go and Not Rust? by vbezhenar on Monday September 16, 2019 @03:53PM (#20987918)
Java is one example of modern language without proper generics. They have syntax sugar for Object references, but you can do almost the same with golang using interface{}.
Re:Why Go and Not Rust? by excursionist on Monday September 16, 2019 @04:26PM (#20988226)
I'm not sure what you mean by 'proper generics', but Java does have compile-time generics, ie List<T>, <A, B> B foo(A bar), etc.
Re:Why Go and Not Rust? by vbezhenar on Monday September 16, 2019 @06:00PM (#20988992)
Proper generics would allow you to parameterize with all types including primitive ones, not just Objects. Check out java.util.Arrays class as an example of why Java's generics are not proper: https://docs.oracle.com/javase/7/docs/api/java/util/Arrays.h...
Re:Why Go and Not Rust? by leshow on Monday September 16, 2019 @07:03PM (#20989438)
You've got a kind of made up definition of 'proper'. Java has generics, they don't have the best implementation of it I've seen, but I wouldn't call it 'improper'. It's just not a word that has any specific meaning in this context.

I seem to remember an article being written a while ago that found Java's type system, with the addition of generics, was unsound. Maybe that's what you're trying to say.

Re:Why Go and Not Rust? by vbezhenar on Tuesday September 17, 2019 @07:36AM (#20993781)
Java generics is a syntax sugar. They don't add anything substantial. You can use Object (or another bound type) everywhere you're using generic type. You only need to add few explicit casts, which are added by compiler anyway.

You can do exactly the same thing in Golang. Just use interface{} everywhere and add few casts where needed. That is Java generics.

Re:Why Go and Not Rust? by excursionist on Tuesday September 17, 2019 @09:55AM (#20995090)
> Java generics is a syntax sugar.

That's not true, Java generics are not just syntactic sugar.

> They don't add anything substantial.

They add parametric polymorphism and type safety.

> You can use Object (or another bound type) everywhere you're using generic type.

Only if you go out of your way to do so, and ignore warnings. This has less to do with how generics work in Java and more to do with the fact that Object can be explicitly cast to another type and vice versa.

> You can do exactly the same thing in Golang. Just use interface{} everywhere and add few casts where needed.

No, it's completely different.

Re:Why Go and Not Rust? by ori_b on Monday September 16, 2019 @03:46PM (#20987858)
Yes, I know what it's called. I have implemented generics in compilers. I still don't miss them in most go code, in practice.