www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Go has contempt for generics

reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
http://www.reddit.com/r/programming/comments/c93iy/go_at_io_frequently_asked_questions/

"Do you have plans to implement generics?
Many proposals for generics-like features have been mooted both publicly 
and internally, but as yet we haven't found a proposal that is 
consistent with the rest of the language. We think that one of Go's key 
strengths is its simplicity, so we are wary of introducing new features 
that might make the language more difficult to understand. Additionally, 
the more Go code we write (and thus the better we learn how to write Go 
code ourselves), the less we feel the need for such a language feature."

That has Java 1994 written all over it.


Andrei
May 28 2010
next sibling parent reply Jonathan M Davis <jmdavisProg gmail.com> writes:
Andrei Alexandrescu wrote:

 
http://www.reddit.com/r/programming/comments/c93iy/go_at_io_frequently_asked_questions/
 
 "Do you have plans to implement generics?
 Many proposals for generics-like features have been mooted both publicly
 and internally, but as yet we haven't found a proposal that is
 consistent with the rest of the language. We think that one of Go's key
 strengths is its simplicity, so we are wary of introducing new features
 that might make the language more difficult to understand. Additionally,
 the more Go code we write (and thus the better we learn how to write Go
 code ourselves), the less we feel the need for such a language feature."
 
 That has Java 1994 written all over it.
 
 
 Andrei
I had a professor who felt that Java hadn't become a "real" language until it added generics. Things were too nice and neat before that. Now, there are a number of things - particularly surrounded generics - which are fairly complicated and nuanced in Java (frequently because they did generics by erasure). So, there's definitely more to trip you up, but it's more useful too. There are definitely choices which can be made with a language which reduce the number of programming errors, but there are a lot which also seriously restrict you. Sure, Java worked without generics. It works without function pointers too. But the lack of generics was frustrating, and the lack of function pointers is still frustrating. The ommission seems alsmost criminal. You _can_ do a lot with a really stripped down language, but if you strip out too much, it can be highly frustrating for the programmer, and it will likely lead to other types of bugs when programmers are forced to do things differently. But if Go doesn't have generics then that's a _huge_ difference from D, since D's templates are definitely some of the most powerful out there. And some of the language features - such as static if - make it possible to do stuff in D that would require template metaprogramming in C++, so D has actually simplified things by making the language more powerful. So, while some folks seem to want to draw comparisons between Go and D, it sounds like there are definitely things about them which are drastically different, not only in the design, but in the philosophy behind the design. - Jonathan M Davis
May 28 2010
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 05/28/2010 08:39 PM, Jonathan M Davis wrote:
[snip some good points]
 So, while
 some folks seem to want to draw comparisons between Go and D, it sounds like
 there are definitely things about them which are drastically different, not
 only in the design, but in the philosophy behind the design.
If Go has only a black stare as a response to problems usually tackled by generics in contemporary language, I wouldn't call that a different philosophy, I'd call that a lacuna therein. Andrei
May 28 2010
parent reply Jonathan M Davis <jmdavisProg gmail.com> writes:
Andrei Alexandrescu wrote:

 On 05/28/2010 08:39 PM, Jonathan M Davis wrote:
 [snip some good points]
 So, while
 some folks seem to want to draw comparisons between Go and D, it sounds
 like there are definitely things about them which are drastically
 different, not only in the design, but in the philosophy behind the
 design.
If Go has only a black stare as a response to problems usually tackled by generics in contemporary language, I wouldn't call that a different philosophy, I'd call that a lacuna therein. Andrei
Curse you for making me increase my vocabulary! ;) Nice word, lacuna... In any case, while I would agree with you that it generally works better for a language to have generics of some kind, there are plenty of languages which get by just fine without them. I haven't looked into Go at all, so I don't know how they would affect it if you added them or what frustrations currently exist without them. But you can have perfectly good languages without generics, and there probably are languages where it would be a bit awkward or needless to have them (probably primary in functional and/or dynamically-typed languages). It could be that Go works great without them, so I'm not sure that it's necessarily a lacuna, but certainly my first reaction without looking more closely into the matter would be that it probably is a lacuna. But whether it really is a lacuna or not would really depend on what they have and how the lack of generics affects them. So, I guess that I'm agreeing with you on the condition that Go really is the kind of language that should have generics, but not being familiar with the language, I can't really say. Regardless, I'm very glad that D has powerful generics in its templates. And they retain and improve on some of the more powerful aspects of C++'s templates rather than being used pretty much purely for container types like are on templates and template metaprogramming, that should come as no surprise. That would also be suggestive of why you'd find a language without them to be lacking. - Jonathan M Davis
May 29 2010
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 05/29/2010 04:42 AM, Jonathan M Davis wrote:
 In any case, while I would agree with you that it generally works better for
 a language to have generics of some kind, there are plenty of languages
 which get by just fine without them.
Yah, it's not the generics per se. That's why I mentioned "response to problems usually tackled by generics in contemporary languages". More dynamic languages achieve things in different ways. But Go seems to claim that built-in arrays, hashes, and channels are all you'll ever need that's generic. I believe that's a mistake. Andrei
May 29 2010
prev sibling next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Andrei Alexandrescu:
 That has Java 1994 written all over it.
Java today can be the most used language, so despite its faults, probably it was good enough. Even if Go has no templates, it has plenty of time to add them five years from now :-) (And in the end templates aren't the only way to design a type-generic language). Bye, bearophile
May 28 2010
next sibling parent reply Jonathan M Davis <jmdavisProg gmail.com> writes:
bearophile wrote:

 Andrei Alexandrescu:
 That has Java 1994 written all over it.
Java today can be the most used language, so despite its faults, probably it was good enough. Even if Go has no templates, it has plenty of time to add them five years from now :-) (And in the end templates aren't the only way to design a type-generic language). Bye, bearophile
I'd argue that Java suffers from the fact that they added generics late in the game. Generics by erasure brings no benefits except backwards compatability, and they cause a whole host of problems for people trying to use them. Yes, you _can_ add things like generics into the language later, but it can be quite disruptive to do so, and the result could be subpar due to constraints such as backwards compatability. Sure, you _can_ use a language without generics (and many other features) and get a lot done, but I'd argue having simplicity as your prime directive tends to lead to an inefficient tool for the programmer. Simplicity should be a goal, but there are times that it should be overridden by other goals. - Jonathan M Davis
May 28 2010
parent Walter Bright <newshound1 digitalmars.com> writes:
Jonathan M Davis wrote:
 Sure, you _can_ use a language without generics (and many other features) 
 and get a lot done, but I'd argue having simplicity as your prime directive 
 tends to lead to an inefficient tool for the programmer. Simplicity should 
 be a goal, but there are times that it should be overridden by other goals.
Another way to say that is that if the cost of simplifying the language is pushing the complexity off onto the user code, it's a poor tradeoff.
May 28 2010
prev sibling parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 05/28/2010 08:44 PM, bearophile wrote:
 Andrei Alexandrescu:
 That has Java 1994 written all over it.
Java today can be the most used language, so despite its faults, probably it was good enough. Even if Go has no templates, it has plenty of time to add them five years from now :-) (And in the end templates aren't the only way to design a type-generic language).
No language has plenty of time for anything. And the major problem with Go is that its authors seem to not get type genericity at all and try to pretend it doesn't exist. That is a pernicious mistake that will cost that language dearly. (This happened with early Java as well; one hallmark of Java is that it talked out of existence all necessities of modern languages until it adopted them, invariably too late to be properly integrated.) FWIW my impression of Go is veering quickly from "well what can you ask? it's unfinished" to active dislike. They don't know what they're doing. Andrei
May 28 2010
prev sibling next sibling parent reply Alex Makhotin <alex bitprox.com> writes:
Andrei Alexandrescu wrote:
 
 That has Java 1994 written all over it.
 
 (This happened with early Java as well; one hallmark of Java is that it talked
out of existence all necessities of modern languages until it adopted them,
invariably too late to be properly integrated.)
And what happened to Java? Looking at the popularity of Java: http://www.devtopics.com/most-popular-programming-languages/ http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html http://langpop.com/ If the Go will reach the same results... future will tell. And, by the way, where's the popularity of the D? As I understand from the Go docs http://golang.org/doc/go_lang_faq.html
 Why does Go not have generic types?
 
 Generics may well be added at some point. We don't feel an urgency for them,
although we understand some programmers do.
 
 Generics are convenient but they come at a cost in complexity in the type
system and run-time. We haven't yet found a design that gives value
proportionate to the complexity, although we continue to think about it.
Meanwhile, Go's built-in maps and slices, plus the ability to use the empty
interface to construct containers (with explicit unboxing) mean in many cases
it is possible to write code that does what generics would enable, if less
smoothly.
 
 This remains an open issue. 
As you can see there's no "contempt", if this word is applicable at all. Russ Cox recently commented on the topic. http://groups.google.com/group/golang-nuts/browse_thread/thread/3c24dd8e7b083e34/22fbbc72858f4121
 The generic approach is more or less obvious:
Less, if you ask me. http://golang.org/doc/go_lang_faq.html#generics is short but accurate. The rest of your mail reads like someone reveling in having built something complex that actually works. It's an addictive feeling - why do you think there are so many C++ programmers? - but I think in general it is counterproductive. It has been interesting to me to see programmers who have written substantial amounts of Go code, even outside the core Go team, say that on balance they don't really miss generics and would not want to see them unless they fit well with the rest of the language. (Petar just said something like that in one of his Tonika blog posts, and someone else said it earlier on the list.) The kind of explicit type-oriented programming that is exactly the kind of heavyweight clumsy spell everything out for the compiler programming that Go strives so hard not to be. Russ
I hope this comment helps. -- Alex Makhotin, the founder of BITPROX, http://bitprox.com
May 28 2010
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 05/29/2010 01:38 AM, Alex Makhotin wrote:
 Andrei Alexandrescu wrote:
 That has Java 1994 written all over it.
 (This happened with early Java as well; one hallmark of Java is that
 it talked out of existence all necessities of modern languages until
 it adopted them, invariably too late to be properly integrated.)
And what happened to Java? Looking at the popularity of Java: http://www.devtopics.com/most-popular-programming-languages/ http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html http://langpop.com/
Not because of that! Andrei
May 29 2010
prev sibling next sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
Jonathan M Davis:
 Yes, you _can_ add things like generics into the language later, 
 but it can be quite disruptive to do so, and the result could be subpar due 
 to constraints such as backwards compatability.
D didn't have templates for some time. Maybe compile-time function execution plus a type type can replace the need for C++/D/Java style generics :-) Bye, bearophile
May 29 2010
next sibling parent BCS <none anon.com> writes:
Hello bearophile,

 Jonathan M Davis:
 
 Yes, you _can_ add things like generics into the language later, but
 it can be quite disruptive to do so, and the result could be subpar
 due to constraints such as backwards compatability.
 
D didn't have templates for some time.
They showed up much closer to v0.01 than v1.00
 Maybe compile-time function execution plus a type type can replace the
 need for C++/D/Java style generics :-)
 Bye,
 bearophile
-- ... <IXOYE><
May 29 2010
prev sibling parent reply Don <nospam nospam.com> writes:
bearophile wrote:
 Jonathan M Davis:
 Yes, you _can_ add things like generics into the language later, 
 but it can be quite disruptive to do so, and the result could be subpar due 
 to constraints such as backwards compatability.
D didn't have templates for some time.
 Maybe compile-time function execution plus a type type can replace the need
for C++/D/Java style generics :-)
I agree with that. Over time, D has moved very strongly in that direction. I wonder how far that approach could ultimately be taken.
May 29 2010
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 05/29/2010 10:52 AM, Don wrote:
 bearophile wrote:
 Jonathan M Davis:
 Yes, you _can_ add things like generics into the language later, but
 it can be quite disruptive to do so, and the result could be subpar
 due to constraints such as backwards compatability.
D didn't have templates for some time.
 Maybe compile-time function execution plus a type type can replace the
 need for C++/D/Java style generics :-)
I agree with that. Over time, D has moved very strongly in that direction. I wonder how far that approach could ultimately be taken.
Clearly we're still exploring what the best way to carve the territory is, but one trend is clear: * Type-parameterized types and functions for generic programming * Compile-time function evaluation for generative programming Andrei
May 29 2010
prev sibling parent reply Sean Kelly <sean invisibleduck.org> writes:
Andrei Alexandrescu Wrote:

 http://www.reddit.com/r/programming/comments/c93iy/go_at_io_frequently_asked_questions/
 
 "Do you have plans to implement generics?
 Many proposals for generics-like features have been mooted both publicly 
 and internally, but as yet we haven't found a proposal that is 
 consistent with the rest of the language. We think that one of Go's key 
 strengths is its simplicity, so we are wary of introducing new features 
 that might make the language more difficult to understand. Additionally, 
 the more Go code we write (and thus the better we learn how to write Go 
 code ourselves), the less we feel the need for such a language feature."
So they've simplified the language at the cost of more complex user code. They should have just said that they haven't found a proposal they like yet and left it at that.
May 29 2010
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 05/29/2010 10:43 AM, Sean Kelly wrote:
 Andrei Alexandrescu Wrote:

 http://www.reddit.com/r/programming/comments/c93iy/go_at_io_frequently_asked_questions/
"Do you have plans to implement generics?
 Many proposals for generics-like features have been mooted both
 publicly and internally, but as yet we haven't found a proposal
 that is consistent with the rest of the language. We think that one
 of Go's key strengths is its simplicity, so we are wary of
 introducing new features that might make the language more
 difficult to understand. Additionally, the more Go code we write
 (and thus the better we learn how to write Go code ourselves), the
 less we feel the need for such a language feature."
So they've simplified the language at the cost of more complex user code. They should have just said that they haven't found a proposal they like yet and left it at that.
Exactly. This "the more code we write the less we felt a need for genericity" reflects very poorly - just not on genericity. Andrei
May 29 2010