News for hackers. Stuff that matters.
Re:Generics aren't ready for Go by jstimpfle on Monday February 18, 2019 @09:36AM (#19190806)
Go has a kind of generics that also maps cleanly to machine-level generics: interface{}, which is like void* in C.

Whereas all the other kinds of generics, I believe, can't offer this quality. They require a lot of machine code instanciations (like C++'s template system). Or at least, in the case of virtual functions ("dynamic polymorphism" with VTables), they cause more brittle abstraction boundaries. Think how in C++, when definining a class, you need to expose a lot of internal details in the header file -- list all the private member functions and fields, etc. This has lead to the so-called PIMPL idiom which is exactly what you do in Go or C.

Re:Generics aren't ready for Go by ben-schaaf on Monday February 18, 2019 @09:58AM (#19191026)
If void pointers are "generics" as you say, then the word is pretty much meaningless. Every language I know of supports that kind of construct and you can usually dump it everywhere as much as you like.

Generics specifically refer to the parameterization of types using types. Go doesn't have user defined generics.

The only reason in C++ why you need to define all the "internal details" in the header file is because the compiler needs to know the size of things. You can write completely template free code that requires all your classes to be defined in headers or you can litter your code with templates, put pointers everywhere and place all your classes outside of headers. It has nothing to do with generics and everything to do with how the rest of C++ is designed.

Re:Generics aren't ready for Go by jstimpfle on Monday February 18, 2019 @10:11AM (#19191154)
Thanks for the correction, I shouldn't say "generics". But rather "Go programmers don't have user-defined generics, they use interface{}" or something along those lines.

Other than that, I don't think we're in disagreement here.

Re:Generics aren't ready for Go by pjmlp on Monday February 18, 2019 @09:41AM (#19190853)
You don't need to expose any internal details on other languages that make use of generics.

Even on C++ this is be eventually a thing of the past, after modules get finally adopted.

Using how C++ currently does as argument against generics is a pretty weak argument, given the various ways to implemente them since CLU and ML introduced generic programming into the world.

Re:Generics aren't ready for Go by jstimpfle on Monday February 18, 2019 @09:45AM (#19190899)
Layouts of separately compiled classes/structs must still be exposed to the compiler. You can't hide layouts away, they are part of the interface. With all the disadvantages that dependencies bring.

> Using how C++ currently does as argument against generics is a pretty weak argument, given the various ways to implemente them since CLU and ML introduced generic programming into the world.

I would be interested to know how you think the problem of tighter coupling (a.k.a dependencies) is solveable, because I don't see a solution. For example, I'm pretty sure that typeclasses in Haskell are implemented with either of those two approaches I've mentioned depending on the situation.

(Maybe it's possible if we require more information for the linker? I haven't thought through this.)

Re:Generics aren't ready for Go by pjmlp on Monday February 18, 2019 @10:04AM (#19191085)
Exposed to the compiler doesn't imply exposed to everyone else to see.

It is solvable by not sitting in an ivory tower using C++ and Java as the typical examples why Go won't get generics, and instead engage with generics friendly communities.

Re:Generics aren't ready for Go by jstimpfle on Monday February 18, 2019 @10:13AM (#19191180)
> Exposed to the compiler doesn't imply exposed to everyone else to see.

Personally I care about true, hard dependencies much more than that "exposed for everyone else to see" fluff (the latter being only a subset of the former). Probably that is because I don't do business software, don't work in big teams etc.

What really matters to me is reducing hard technical dependencies, and recompile times and ABI compatibility may only be the two biggest reasons.

You're probably aware that I program predominantly in C, and "sitting in an ivory tower" is not a word that I would apply to typical C programmers. I wouldn't apply it to Java programmers, either. It's normally a term for the academic world, the world from which languages that focus on type theory originate.

Re:Generics aren't ready for Go by pjmlp on Monday February 18, 2019 @10:31AM (#19191342)
I am applying that term to Go developers against generics no matter what.

C does provide minimal support for generics since C11, with improvments planned for later standard revisions, as anyone that works predominantly in C should be aware.

And yes I am aware that I kind of reversed the meaning of the term, but that is how it feels all the Luddite arguments against generics.

Just because there are plenty of old tech languages, which many in the generics crowd have a large experience using, doesn't mean we should keep using such approach at expense of productivity.

Re:Generics aren't ready for Go by jstimpfle on Monday February 18, 2019 @10:38AM (#19191400)
> I am applying that term to Go developers against generics no matter what.

They are actively looking for something that doesn't suck. Aren't they?

> C does provide minimal support for generics since C11, with improvments planned for later standard revisions, as anyone that works predominantly in C should be aware.

Not sure what was your intention behind that statement. But of course I'm aware of C11 Generics. And they might be nice for a generic min() and max() and similar but other than that honestly I have little use because types are not values and in C, types are not elevated to be much more than simply physical layout. Whenever I've tried to encode meaning in types in any language I've failed spectacularly. Feel free to make Oddintegers and Evenintegers all day long if that's what makes you happy.

> And yes I am aware that I kind of reversed the meaning of the term, but that is how it feels all the Luddite arguments against generics.

Let's get a life and not spend all of our time raging against people doing different things differently. At Google, I'm sure Go does solve real headaches they have with C++ ((re)compilation issues being only the worst offenders) and Python (performance...). And probably it does so better than any other language can. Because, Google is still primarily an engineering company, not a hipster company, nor a language-obsession company.

Re:Generics aren't ready for Go by pjmlp on Monday February 18, 2019 @11:21AM (#19191760)
> They are actively looking for something that doesn't suck. Aren't they?

It looks more of "we are working on it excuse" to keep people at bay.

Rob Pike has done a presentation last year where he stated that he doesn't have anything to do with it and is very sceptical of it being ever added.

So WIP is kind of euphemism.

> Not sure what was your intention behind that statement.

That even languages born before generics are willing to move forward.

Google is majorly a Java, Python, C++ shop. Go is usually more outside than internal Google projects.

If we reduce Go lack of features to stuff that C doesn't provide, maybe bounds checking, modules and GC aren't required as well.

As for complaining, projects like Docker and K8s ensure that those of us that rather not use Go, have to deal with it in some form anyway.

Re:Generics aren't ready for Go by jstimpfle on Monday February 18, 2019 @12:12PM (#19192173)
> If we reduce Go lack of features to stuff that C doesn't provide, maybe bounds checking, modules and GC aren't required as well.

Well that was the initial basic design frame: A systems programming language that removes some of the headaches of writing distributed systems software with the use of a GC and Channels/CSP.

It was intended from the start to have more features and tradeoffs than C has, and it even backed up pretty quickly from trying to be a competitor in the (not-distributed) systems programming space, didn't it?

> That even languages born before generics are willing to move forward.

C11 Generics are a pretty limited feature, basically a central switch on types instead of values. They are not a big deal. And maybe Go decided against them because Go has RTTI. In any case, C11 Generics are decidedly different from what many people expect from a Generics in Go.

> As for complaining, projects like Docker and K8s ensure that those of us that rather not use Go, have to deal with it in some form anyway.

Dude... 1) They are not Go. 2) If you don't like them don't deal with them. 3) Don't make an elephant from a mosquito. 4) Show us some of your beautiful systems software written in perfect OOP style in languages from 1975 already! We need real world proof that there is a supreme super-typesafe OOP way with functional bells that solves all of our problems!

Re:Generics aren't ready for Go by pjmlp on Monday February 18, 2019 @02:44PM (#19193677)
C++ comes to mind.

Also some would say that Go is actually from 1968.

http://cowlark.com/2009-11-15-go/