4 ms·
I read through this yesterday and I'm fairly confused about all that. 1. This is a long proposal. Excluding the implementation/issues/comparison parts, it cloc
by drej 7y ago
I read through this yesterday and I'm fairly confused about all that.
1. This is a long proposal. Excluding the implementation/issues/comparison parts, it clocks in at 7700 words. Compared to the 27k-word long Go spec, this is epic. I know the proposal is more verbose than the eventual spec (if accepted), but still...
2. There are some valid points in Nate Finch's criticism of the previous proposal (https://npf.io/2018/09/go2-contracts-go-too-far/ https://npf.io/2018/09/go2-contracts-go-too-far/). Be it philosophical arguments or just plain syntax ones - like writing `func (...)(...)(...)` in function declarations.
I don't know. I'd like some form of generics in the language, but I'm not sure if complex designs like this are likely to be embraced by the community.
- Cthulhu_ 7y agoI think the complexity / length is a good indication as to why there's resistance to adding generics to Go; frequently, Java generics are cited since (and this is from the top of my head) it almost doubled the size of both the Java spec and its implementations (compiler, runtime). That is a lot of complexity to manage, and runs counter to what I believe is the current mindset of the Go language. And in Java it didn't stop there; the people (person?) behind generics moved on to create Scala, a language with even more features and a notoriously complicated 25-step compilation process (see https://typelevel.org/scala/docs/phases.html https://typelevel.org/scala/docs/phases.html) (compare with Java's six phases https://www.javatpoint.com/compiler-phases https://www.javatpoint.com/compiler-phases and Go's... three? Not sure, I found https://getstream.io/blog/how-a-go-program-compiles-down-to-machine-code/ https://getstream.io/blog/how-a-go-program-compiles-down-to-...). edit: Actually most of my knowledge comes from https://news.ycombinator.com/item?id=9622417 https://news.ycombinator.com/item?id=9622417, I had bookmarked it.
- apta 7y ago> And in Java it didn't stop there; the people (person?) behind generics moved on to create Scala, Java and Scala are two very different languages, it doesn't makes sense to compare them. What you're suggesting is basically a slippery slope fallacy.
- msbarnett 7y ago> And in Java it didn't stop there; the people (person?) behind generics moved on to create Scala, a language with even more features and a notoriously complicated 25-step compilation process What does this have to do with anything? Scala is complex to compile for reasons far, far beyond generics. Are generics somehow guilty by association because an engineer who was once involved in an implementation of them went on to build some other complex thing?
- cinnamonheart 7y agoI don't think generics necessarily need to have a complex specification. Standard ML's specification, despite parametric polymorphism and parameterised modules, is incredibly small and easy to understand.
- Footpost 7y agoI'm afraid that's not the case. Generics are very easy to implement under the following reasonable conditions: 1. you don't care about performance (you simply 'box' everything), 2. you don't care about executable size (you simply specialise every generic definition to their concrete use cases -- this is what C++ compilers do), 3. you don't do reflection on types in generic definitions. As "cinnamonheart" mentions in a sibling post, ML's generics are straightforward, and remain, despite hailing from the 1970, even today a shining example of programming language design. Unfortunately, Scala had to violate all three points above to maintain compatibility with Java, and the JVM.
- erik_seaberg 7y agoThe compiler should do as much work as it possibly can. The alternative is making me do it at 0.0001 MHz because I'm made of meat.
- benhoyt 7y agoThe draft design is long, however, I don't think by itself that's an indication of complexity, and this would be a fraction of the size in the actual spec. This is tutorial-like in places, with many code examples (more than a third of the doc), and a whole section (somewhat less than a third) on issues and discarded ideas.
- the_duke 7y agoI agree that the proposal is far from succinct. But it is not really written a s a technical proposal, more an explanation with plenty of detail and abundant examples. The important information is kind of drowned out by the noise. But other than that it is not really that complex. Generics aren't easy, but they are not something that needs to be invented. Implementation options and tradeoffs are well understood. The duplication introduced by having both concepts and interfaces is unfortunate though. Regarding syntax: No language has really managed to provide a really good syntax for generics, imo. The default <T> is often ugly. Haskell chose to have them declared in a separate function header which is much nicer, but also annoying when having to modify two lines, etc. I think this is a reasonable tradeoff. With special syntax highlighting for `(type T)` it will be easy enough to parse visually. The proposal does contain some particularly unfortunate examples though.
- skybrian 7y agoIt doesn't have contracts, but Zig's syntax seems pretty good: https://ziglang.org/documentation/master/#comptime https://ziglang.org/documentation/master/#comptime
- 013a 7y agoThis proposal is so hilariously complex relative to everything else in Go, I have to wonder if the Go team has already decided that they aren't adding Generics; they release a galaxy brain generics proposal which even the strongest proponents of the feature have to admit is way too much, it inevitably gets struck down, and now they can say "look team, we tried and you said you didn't want generics." Genius level play from Ian and Robert.
- geodel 7y agoPerhaps a 3-part medium post or a series of 10 tweets be more suitable for most discussed (lack of) feature for years?
- deleted 7y ago[deleted]
- JyB 7y ago> but I'm not sure if complex designs like this are likely to be embraced by the community. Spoiler alert: It won't. If you think the Go community had a strong reaction with `if err != nil`, just wait for this one.