Go core team is working hard to bring generics to the language because several people asked for it. With all due respect for those users and for people working hard to make generics a reality, I feel that a greater number of people would suffer after generics adoption. So, I feel compeled to manifest my opinion: sorry guys, Go with generics will be worse than Go without generics.
The language strives for simplicity since its inception and that is what attracted a large part of its user base. We must think about who we will want to have in our community 10 years from now. Supporting generics would please a minority to the detriment of a large number of potential users.
Today Go is easy to learn and tools are easy to implement. Please keep it that way.
Pondering this, my concern is that it might become too powerful. I'm scared this will make it harder to work out what someone has done if there's too much indirection and magic added on top. It feels like it could be a really *really* big hammer.
Pondering this, my concern is that it might become too powerful. I'm scared this will make it harder to work out what someone has done if there's too much indirection and magic added on top. It feels like it could be a really *really* big hammer.I don't buy the argument " those who prefer to avoid generics may do so and carry on as they are" because go is all about large projects and code reuse. If you enable people to write code that the average programmer can't understand, then IMO that is against the philosophy of what i thought go was.
It would be nice, for example, to have a full range of collection types in the standard library without the need to use interface{}, type assertions and the performance overhead of 'boxing'.
I am going to refer everyone involved in this discussion on generics to this once again. I know it is long, read the summary... but it’s important:
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/3ia8XrUgqOg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
func (x type []K) Sum() (r type K) {
for type switch {
case K range int64(), uint64(), float64(), complex128():
for _, v := range x {
r += v
}
case K big.Int:
for _, v := range x {
r.Add(r,v)
}
break // or return in every case instead
}
return
}
func Sum(some []K, add func(l,r K) K) (ret K) {
for _, v := range some {
ret = add(ret, v)
}
return ret
}
func addOperator(l,r Z)Z{
return l+r
}
func main(){
total := Sum([]rune("whatever"), addOperator)
}
Go core team is working hard to bring generics to the language because several people asked for it. With all due respect for those users and for people working hard to make generics a reality, I feel that a greater number of people would suffer after generics adoption. So, I feel compeled to manifest my opinion: sorry guys, Go with generics will be worse than Go without generics.The language strives for simplicity since its inception and that is what attracted a large part of its user base. We must think about who we will want to have in our community 10 years from now. Supporting generics would please a minority to the detriment of a large number of potential users.Today Go is easy to learn and tools are easy to implement. Please keep it that way.
Thanks.
The opinion that well, since there is no implements I can define my own interface, and pass some stdlib struct that I can’t control as an “implementor” is hogwash. Because you also don’t control this code, the API is free to change - breaking your code. This is why the “backwards implements” is a bad idea.
It is time for everyone to take a break for 48 hours. After this time if you feel strongly that there is a point which you must continue to debate please do so, but be mindful that many words have already been spent in this thread and the points of view expressed are unlikely to change.
Thank you
Dave
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
[Apologies to Dave Cheney, timely pushback for David Collier-Brown]David, I disagree and suggest your remark is not well considered. Three replies, one per sentence.
"Right now, this looks like the third draft of an academic project."Not to me. This reads like years of thought and discussion among qualified researchers and skilled implementers. Not to boast unduly, but if you look at the history of Ian, Robert, and Russ, you'll see intimate responsibility not only in Go but in Gnu C/C++, Modula, and more. What I see in the proposal is informed wisdom. This is engineering so there is always a better way, but this may be the best that can be seen before implementation and experience.
"It suffers badly by comparison to make(), the existing mechanism."Yes, inherently so. The existing mechanism uses magic in parsing and implementation—details known in the compiler but not exposed in the Go language generally, to make things as easy as possible. It is nice. But from before the launch of Go users asked "how can I do such things generally, in my code, and not by extending the language or the compiler." The answer was "use interfaces now and we'll think about generics later." Later is now and indeed exposing aspects of behind the scenes compiler magic is more complicated, that's inherent. The decision to be made is how powerful vs how complicated.
"Can we see some more alternatives, please?"They are legion. Existing generics approaches in various languages are more than ideas, they are living examples of design, ecosystem, and behavior. Several proposals have been offered by the Go team and collaborators here. The Go 2 design site lists many specific comments and alternatives. Extensive thoughts have been shared, with responsa sunt, novi in via.
This is something that I have seriously considered to be the right way for Go to express other generic types. I am in fact in the middle of a project at the moment where I have created a pair of generic byte buffer types, one is the regular kind, the other uses memguard locked buffers, for keeping secrets out of reach of other processes on a system.
i instantiate a tree type to handle uin64 data. under the proposal, this should work because guards assert that the type proposed must allow "==" to be used.i instantiate with some custom type that needs its own custom "isEqual(a,b)" -- that will not instantiate because there is no "==" operator for my custom type, even though there is an equality tester but its name is not "==" and i can't overload "Operator==" to say so.
one way is to have operator overloading so my type has equivalence testing under a standard name. (==)one way is to instantiate with the type name and a "test for equal" function pointer that when nil means "just use =="one way is to annotate my type's "isEqual()" a la json annotation with a hint saying "use this for equality testing"
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think the thing everyone who likes operator overloading like mainly is being able to do infix and postfix syntax, instead of only prefix (function).
But then also what do you do about interfaces that also implement an operator interface? I'd guess biggest reason to not do it is1) no human readable distinction between actual operations and one has to decompose the code quite a lot as both types have to be known before you can attach it to an interface2) there is very few cases where being able to use infix operators makes that much difference to readability, it's like you want some mathematical notation but it's still all in lines. Chaining pass-through methods works just as well and the types are much easier to identify before you even fully parse it.
gopher: Will you want to test for equality, madam?type: Yes, thank you.gopher: How would you prefer that test to be done?type: Hmm... I'll try 'IsEqualWithOddName(a, b *type)" for now.gopher: very good, madam.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
>> 2. mailto:golang-nuts+unsub...@googlegroups.com
>> 3. https://groups.google.com/d/optout
>> 4. mailto:michae...@gmail.com
>> 5. mailto:golang-nuts+unsub...@googlegroups.com
Venners:The opposite of complexity is simplicity. I have often heard you describe your philosophy when designing Java in the early days: you didn't put something in Java unless five people screamed at you and demanded it. In one interview, you told this really good story about moving to a new apartment and something about keeping things in boxes.
Gosling:That's actually a general principle for life that works really well. When you move to a new apartment, don't unpack. Just sort of move in, and as you need things, pull them out of the boxes. After you've been in the apartment for a couple of months, take the boxes -- don't even open them -- and just leave what's in there and throw them out.
Venners:The 'don't even open them' part is important because it's very hard to throw things away once you know what they are.
Gosling: Right, because if you open them, you say, 'oh, I can't part with that.'
Venners:So would you say that simplicity is a general philosophy programmers should always have when designing programs?
Gosling:I think in any kind of design, you must drive for simplicity all the time. If you don't, complexity will nail you. Dealing with complexity is hard enough.
In programming language design, one of the standard problems is that the language grows so complex that nobody can understand it. One of the little experiments I tried was asking people about the rules for unsigned arithmetic in C. It turns out nobody understands how unsigned arithmetic in C works. There are a few obvious things that people understand, but many people don't understand it.
So one of the most important criteria for judging a design for me is the manual. Is the manual out of control, or is it reasonably concise? You can write a pretty decent Java manual in less than 100 pages. The current Java language spec is pretty thick, but that's because it's probably the most detailed language spec ever written. It goes through all of the details. I couldn't write the Java language spec.
>>>> 2. mailto:golang-nuts+unsub...@googlegroups.com
>>>> 3. https://groups.google.com/d/optout
>>>> 4. mailto:michae...@gmail.com
>>>> 5. mailto:golang-nuts+unsub...@googlegroups.com
>>>> 6. https://groups.google.com/d/optout
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an
>>> email to golang-nuts...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>
>
> --
> Lucio De Re
> 2 Piet Retief St
> Kestell (Eastern Free State)
> 9860 South Africa
>
> Ph.: +27 58 653 1433
> Cell: +27 83 251 5824
> FAX: +27 58 653 1435