News for hackers. Stuff that matters.
Re:Summary of Golang Generics Discussion by coldtea on Tuesday December 16, 2014 @07:32AM (#8756827)
>As with any feature it should solve a set of problems, if the problem isn’t solved in the best way possible by the feature then it’s either not a good feature or of very limited value.

This is disingenuous -- just to set an artificial barrier against generics.

Go doesn't solve any problem in the "best way possible":

- "Blessed" containers like Go's hash tables are not "the best way possible".

- The way it handles goroutines/channels has issues (mutability/pointer issues, not pre-emptive, etc). Again, far from "the best way possible" (that would be Erlang maybe).

- The GC was far from the "best way possible" or even "really good". Especially on the earlier versions (and crap on 32-bit).

- Losing type checks by having to use interface{} for generality, or resolving to BS textually generated code with custom string templating is not "the best way possible".

So why only Generics has to be "perfect or bust"?

And then there's this gem, about the (lack of) need for generic data structures:

>map/slice suffice for most of the cases encountered in programming.

...

Or this "con", about having generic to help with functional fold/zip/map:

>The fastest solution needs to take into account when and which order to apply those transformations, and how much data is generated at each step

So, in other cases the hit from interface{} is OK, but suddenly now those operations have to be "the fastest solution".

(Not to mention that the fastest solution, application order etc are orthogonal to Generics).

Re:Summary of Golang Generics Discussion by egonelbre on Tuesday December 16, 2014 @09:38AM (#8757289)
Thanks, didn't intend for it to end up on HackerNews - at least not yet. It's still the first draft, most of it I wrote up in ~2hours. I mentioned on the forum that this document (currently) is highly biased towards my views, this is unfortunate, but this can only be fixed after numerous reviews.

Thanks for pointing out the problems with wording. I'm slowly fixing those. I've changed that "best" to "As with any feature it should solve a set of problems, if there are better ways of solving the problems, those should be used instead."... it's better but not perfect.

"in other cases the hit from interface{}" - added that addition to the alternatives section.

Generics don't have to be perfect, but it must be actually useful and it mustn't compromise simplicity of Go.

Re:Summary of Golang Generics Discussion by coldtea on Tuesday December 16, 2014 @10:45AM (#8757597)
>* Thanks, didn't intend for it to end up on HackerNews - at least not yet. It's still the first draft, most of it I wrote up in ~2hours. I mentioned on the forum that this document (currently) is highly biased towards my views, this is unfortunate, but this can only be fixed after numerous reviews. Thanks for pointing out the problems with wording.*

Thanks for not being defensive and taking my rather harsh critique lightly!

I wasn't trying to attack your specific document either, it's just that those things have often been repeated (often verbatim) by the Go-dev camp.

Re:Summary of Golang Generics Discussion by egonelbre on Tuesday December 16, 2014 @10:57AM (#8757648)
Basically, I have nothing to be defensive about - it's a summary of discussions, which means that any properly stated argument should be incorporated to the document, no matter what I personally feel about that argument. Although, the content has to be moderated somehow, I dislike deciding what is "properly stated" argument, but I don't really have a better idea how to do it either, at least not yet.

Personally, I stand in the middle of the generics discussion so I pretty much can see both sides as a valid approach. And it's a WIP and I know if one person writes it, it will be biased no matter how hard you try.

PS: I find the "straight to the point" comments much more useful - they are much easier to understand. So don't worry about it :)

Re:Summary of Golang Generics Discussion by NateDad on Tuesday December 16, 2014 @10:02AM (#8757402)
Put a big comment on the top DRAFT!! STILL IN PROCESS!! or something.
Re:Summary of Golang Generics Discussion by waps on Tuesday December 16, 2014 @10:12AM (#8757448)
It doesn't mention the major inconsistencies in golang at all.

Go has generics. For arrays, slices, channels, maps, and some "standard" library functions. Go has generic functions. "append" being the obvious example. Go has polymorphic functions : append, make, ... If you look at the compiler source, the type system has generics, to a large extent. It's simply not accessible to normal programmers, instead only allowed for golang's authors.

As if this is not bad enough. Go cheats the type system in thoroughly non-obvious ways to get more C-like behaviours that obviously do not improve safety or programmer productivity.

Go has shudder return value polymorphic functions. Range being the obvious, but not only example (range changes in meaning depending on it's parameters AND on what you assign the result to).

As for your boxing argument. As soon as you use reflect, you're boxing everything. Oh wait, if you use a package that uses reflect, of course you're also boxing everything. Surely that can't be much ... hmmm half the standard library uses reflect. Fmt, everything in encoding, text or html templates, rpc, jsonrpc ... No need for boxing, or compile-time function evaluation or generics (all present better solutions to this, for the CTFE solution see D-lang).

Golang even has functions with type parameters. Make and new being the obvious examples. Again, this is present in the type system (not just there, also in reflect, things like printf, ...). It's simply not made accessible to us lowly go programmers.

So can we please stop with the crap that generics aren't necessary ? That nobody uses advanced type system features ? Or that polymorphism isn't necessary ? It's crap, and obviously the golang authors don't actually believe that. They just think that only they can be trusted to write such functions and that their datastructures are all anyone ever needs. If you disagree with that assessment (and everybody will, soon) Go is not for you.

So Go is simply a throwback to pre-80s programming languages, and a perfect illustration of the frustrations that led to the development and extension of the C++/Java/C# programming languages. If you give people the minimal implementation of sorting an array of structs, it becomes blatantly obvious why other languages are necessary.

The more I write Go, the more I yearn for C++. There is nothing in the C++ language that I can't do for my own datastructures/functions/... That is a huge feature, and may I just say :

From my cold, dead hands !

Btw : there is a better solution to generics as well at compiler-level, that is used in things like the CLR. First, generate unboxed versions of functions where that makes sense. If specializations are possible for 1-bit, 1-byte, 2-byte, 4-byte and 8-byte primitive data types, expand those. Then for anything bigger, like structs, create a boxed implementation, because for structs there is no longer any advantage to working unboxed. Then make it possible to pass in the version to be used in a parameter, so you don't have a combinatorial explosion when many type parameters are given.

e.g. http://research.microsoft.com/pubs/64031/designandimplementa...

Re:Summary of Golang Generics Discussion by ansible on Tuesday December 16, 2014 @11:01AM (#8757663)
Btw : there is a better solution to generics as well at compiler-level, that is used in things like the CLR. First, generate unboxed versions of functions where that makes sense. If specializations are possible for 1-bit, 1-byte, 2-byte, 4-byte and 8-byte primitive data types, expand those. Then for anything bigger, like structs, create a boxed implementation, because for structs there is no longer any advantage to working unboxed. Then make it possible to pass in the version to be used in a parameter, so you don't have a combinatorial explosion when many type parameters are given.

That sounds sensible.

I'd like to figure out a way to extend the concept of interfaces to cover use cases like generic containers, but I'm not quite sure how that would work.

Re:Summary of Golang Generics Discussion by michielvoo on Tuesday December 16, 2014 @04:19PM (#8759574)
Regarding the CLR, the document links to MSDN [1] where it says that "the runtime generates a specialized version".

[1] http://msdn.microsoft.com/en-us/library/f4a6ta2h.aspx

Re:Summary of Golang Generics Discussion by egonelbre on Tuesday December 16, 2014 @11:00AM (#8757660)
> It doesn't mention the major inconsistencies in golang at all.

It has little relevance to "Generics". They are simply how Go is implemented, the question is whether "Generics" as a user implementable thing should be added.

> CLR

From my quick reasearch, it uses runtime code generation and Go must run in environments where that is disallowed.

Re:Summary of Golang Generics Discussion by pjmlp on Tuesday December 16, 2014 @11:18AM (#8757743)
Regarding the CLR you have ahead of time compilers in the form of Mono for iOS, Windows Phone, Bartok, ngen and now .NET Native.

How the generic code generation differs from the JIT approach I don't know.

Re:Summary of Golang Generics Discussion by waps on Tuesday December 16, 2014 @11:24AM (#8757776)
It has relevance to generics. Right now the question implies Go does not have generics, which is not true at all. The question should be reworded :

Go has generic types and generic/polymorphic functions. Therefore all the focus on that such functions are not necessary/useful seems entirely beside the point, the result of misunderstanding. Can normal Go programmers please be allowed to make use of that feature ?

Re:Summary of Golang Generics Discussion by GFK_of_xmaspast on Tuesday December 16, 2014 @07:35AM (#8756831)
"""So why only Generics has to be "perfect or bust"?"""

Ideology, and a push-back against outside pressure to include them.

Re:Summary of Golang Generics Discussion by sigzero on Tuesday December 16, 2014 @08:08AM (#8756916)
Then they should just own it and say "Go isn't getting generics ever." instead of making artificial barriers. Which their explanation totally is doing.
Re:Summary of Golang Generics Discussion by masklinn on Tuesday December 16, 2014 @08:28AM (#8756989)

    $ python -c 'from __future__ import braces'
      File "<string>", line 1
    SyntaxError: not a chance
Whether you agree or disagree, it's not trying to bullshit you with fallacious reasoning.
Re:Summary of Golang Generics Discussion by commentzorro on Tuesday December 16, 2014 @07:50AM (#8756869)
It seems to be a rite of passage that everyone who gets to a certain point of familiarity with Go has to write an article justifying why you don't need generics. Austerity can be a tough way to live until you become a bit numb.
Re:Summary of Golang Generics Discussion by marcus_holmes on Tuesday December 16, 2014 @11:59AM (#8757954)
Another rite of passage is the "logger" library, where every Go coder I know (including me) writes a "better" logging library because the standard one is so terse. A few thousand lines of code later, everyone quietly discards their overcomplex library and reverts back to the standard log.

The same goes for most of the standard library "improvements" that people make. Http middleware is necessary until you grok the power of Handlers, ORMs are prevalent until you get that it's easier to write specific CRUD routines for your structs using the standard lib.

I don't think it's austerity any more. I think it's just putting a high value on simplicity, and I really appreciate that now I understand it better.

I'm happy to let the generics argument rage and smarter people than me resolve it. I don't need generics in my coding, happy to work around the occasional time I'd use them, but I understand the "argument from make" - if the Go team needed generics to build the language, then surely they're a Good Thing and we should have them.

Re:Summary of Golang Generics Discussion by coldtea on Tuesday December 16, 2014 @08:44AM (#8757054)
Re:Summary of Golang Generics Discussion by weberc2 on Monday December 22, 2014 @11:31PM (#8786765)
I don't know. I program in C++ all day long--it took a loooong time to figure out the good patterns in the sea of options or to learn to interpret the cryptic and/or vague error messages (I just got an "invalid use of class" error today with GCC that contained nothing more than a line number for data). And that's not counting the sea of build systems, style guidelines, etc. And even with the generics situation, the amount of boilerplate in Go is a tiny fraction of that in C++.

I'm quite happy to yield control to sane defaults, widely-accepted conventions, and obvious idioms when I'm at home. If I ever need to write some high performance application, I'll definitely consider switching back to C++ (or perhaps learning Rust), but Go is great for rapid development of decently-fast-executing programs.

Re:Summary of Golang Generics Discussion by zerr on Tuesday December 16, 2014 @08:05AM (#8756905)
I think mostly it is an incompetence of Go's designers, no matter how they cover it up...
Re:Summary of Golang Generics Discussion by lucozade on Tuesday December 16, 2014 @08:33AM (#8757012)
If that had been re-worded to "if the problem isn't solved in the most pragmatic way possible" then I would suggest that the sentiment would be a) more in keeping with the general philosophy of Go and b) a justification, sort of, for only supporting map and slice.
Re:Summary of Golang Generics Discussion by Dewie on Tuesday December 16, 2014 @09:01AM (#8757116)
I think you're interpreting that sentence a bit too literally. Clearly the developers of Go are interested in very carefully balancing language features with language complexity (seemingly both for language users and language implementers). And it is in that sense that they probably mean solve in the best way possible, namely to solve a problem in the best way possible with those two concerns - complexity, "expressitivity" - carefully balanced[1].

[1] Though one can argue that the word "best" seems inappropriate when the concern is a very subjective balancing act.