by simonz05 on 7/27/19, 8:45 AM with 61 comments
by tapirl on 7/28/19, 8:59 AM
The new draft improves the contract part. But generic declaration part still looks some verbose. There are many repetitiveness, such as the Map example: https://github.com/golang/proposal/blob/4a54a00950b56dd00964...
func New(type K, V)(compare func(K, K) int) *Map(K, V)
func (m *Map(K, V)) Insert(key K, val V) bool
func (m *Map(K, V)) find(key K) **node(K, V)
func (m *Map(K, V)) Insert(key K, val V) bool
func (m *Map(K, V)) Find(key K) (V, bool)
func (m *Map(K, V)) InOrder() *Iterator(K, V)
And I didn't find how to write a contract which requires a type must have some specified fields in this draft.by latchkey on 7/28/19, 8:31 AM
Initial reading of this document makes me feel it is really over complicated compared with Dart.
by steinuil on 7/28/19, 9:25 AM
Edit: didn't read through the whole thing, I guess contracts can do things that interfaces don't. I think the overlap still makes things a bit awkward though.
by tomohawk on 7/27/19, 9:49 AM
by baby on 7/28/19, 9:05 AM
* letting people being able to abuse them. C++ cough cough.
* making it clear to people reading the code what is happening.
I’ve noticed a few things:
* associated types in Rust are much clearer than generics
* one letter generics are “overly generic” and do not describe enough.
* the declaration of the type really adds verbosity
So what can a language do?
1. Maybe change the syntax to this one:
func eat(food []generic.Type)
Or func eat(food []g::type)
Or something that doesn’t involve adding more <> or ()2. Forbid one letter generic or force a description of the generic or even better: force listing all the types that are currently using this generic NEXT to the generic!
g.type -> {egg, bacon}
func eat(food []g.type)
But then you can’t use a generic from another package... but maybe it’s a good limitation?Or force a generic to have a description, which is what golang is doing with interfaces. The problem is that we can’t combine difference interfaces like in Rust/ocaml
by threeseed on 7/28/19, 9:17 AM
by simonz05 on 7/27/19, 8:50 AM
[1]: https://about.sourcegraph.com/go/gophercon-2019-generics-in-... [2]: https://go-review.googlesource.com/c/go/+/187317/
by MrBuddyCasino on 7/28/19, 10:22 AM
func Print(type T)(s []T)
could be written as func Print(type T implements SomeInterface)(s []T)
What am I missing?by grenoire on 7/28/19, 8:07 AM
by misrab on 7/28/19, 9:47 AM
by johnisgood on 7/28/19, 12:25 PM
by antpls on 7/28/19, 8:55 AM
It would mean moving (and a bit of rewording) "Discarded ideas", "Comparison with Java", "Comparison with C++" before "Design" and after "Background".
As a reader, I prefer to be presented with the problem first (with the constraints and previously explored ideas), then be presented the logical, "obvious", proposed solution.