News for hackers. Stuff that matters.
Re:Golang data structures by vessenes on Saturday July 04, 2015 @01:23AM (#9829330)
It's just not worth using interface. And, I think, by the way, that has always been the intent from a syntax point of view.

The fact that it's slow on the CPU side is not great, but I don't think it's a major problem in the eyes of the core dev team: as far as I can tell, they do not believe that generics support as commonly envisioned is in line with go's mission.

Go is the anti-lisp / anti-unix of languages; designed to not give a team of junior devs enough rope to hang themselves. If we'd like a generics proposal that would get buy-in, I think we need to adhere to that dream while we imagine working generics and propose something; I bet it would be accepted.

Re:Golang data structures by TheHydroImpulse on Saturday July 04, 2015 @01:35AM (#9829355)
sigh. Then you're back at using a more complex solution by copying and pasting generic structures and algorithms.

Moreover, the idea that generics allows junior devs enough rope to "hang themselves" is preposterous. There are more than one type of generic system out there, we don't need to replicate C++ templates here.

Let's not fool ourselves here. There's a difference between "we just haven't figured it out yet" and "generics doesn't fit into the vision of Go". The former attitude is perfectly acceptable. The latter is really annoying and misleading because Go does use generics -- internally.

Re:Golang data structures by djhworld on Saturday July 04, 2015 @03:48AM (#9829575)
> Let's not fool ourselves here. There's a difference between "we just haven't figured it out yet" and "generics doesn't fit into the vision of Go". The former attitude is perfectly acceptable. The latter is really annoying and misleading because Go does use generics -- internally.

I think there's some misconception here, Russ Cox (one of the core Go team) posted this on HN a few weeks ago https://news.ycombinator.com/item?id=9622417

Re:Golang data structures by sambeau on Saturday July 04, 2015 @05:49AM (#9829746)
I wonder if they've spoken to Phil Wadler. Having done Haskell and Java maybe he could get it right for Go?
Re:Golang data structures by timmytokyo on Saturday July 04, 2015 @01:35AM (#9829353)
Isn't that sort of like saying it's not worth using data structures other than maps and slices? In go, if you want a complex data structure you either use interfaces -- as the authors of this library did -- or you rely on some sort of code generation approach.

I've followed the go team's discussion of generics for a long time now. They've always claimed they're open to proposals that fit the philosophy of the language, but they're seemingly not in any hurry to address the issue. And that's fine. But I won't pretend it isn't frustrating every time I want to build something with a non-trivial data structure. Sometimes a map or a slice just doesn't cut it.

Re:Golang data structures by yoklov on Saturday July 04, 2015 @02:43AM (#9829468)
Never used Go, but I've written a lot of C in the past and I think the point you're missing is that they probably intend for you to use a special purpose data structure when a map or slice doesn't fit your needs. When it's special purpose, there's no need to use generics.

When I needed a generic data structure in C, I would do code generation (but only after I'd have a use for it in more than one place). The number of times I ever needed to do this for anything other than an array or hashtable is (not really surprisingly) vanishingly small.

So, coming from the perspective of Go is a better C (that avoids the mistakes of C++), this choice makes sense to me. I don't necessarily think it's the right choice -- I think generally generics are useful, but tend to use generic functions in my C++ code more than generic types or containers.

Might be worth noting that I work in game development, where using a library data structure isn't really considered for most things, because a special purpose one is likely able to be higher performance, due to assumptions it's able to make, operations it doesn't need to implement, etc. I guess I can see the situation where not being able to find an off the shelf generic data structure is frustrating, but I think it might be a bit overblown.

Re:Golang data structures by pcwalton on Saturday July 04, 2015 @02:54AM (#9829488)
You don't ever need a concurrent linked list or hash map?

Lock-free concurrent data structures always struck me as the killer use case for generics as far as data structures are concerned: reasoning about atomics (especially when you have to annotate with relaxed/acquire/release/sequentially consistent ordering) is really tricky and one small mistake will lead to incredibly difficult-to-reproduce bugs. You really don't want to rewrite those over and over. Even something like a j.u.c-style concurrent hash map with striped locking needs careful thought around growth and reallocation lest you deadlock; it's so much easier to just have someone else write the data structure.

Re:Golang data structures by threeseed on Saturday July 04, 2015 @03:26AM (#9829543)
Writing bug free data structure implementations is hard. Doing it in a way that is highly performant is extremely hard.

The idea of cutting/pasting code seems pretty backwards to me compared to just using one of these libraries:

http://java-performance.info/large-hashmap-overview-jdk-fast...

Re:Golang data structures by lolhackernews on Saturday July 04, 2015 @11:18AM (#9830394)
Thing is, in Go that library cannot be written generically.
Re:Golang data structures by jshen on Saturday July 04, 2015 @02:10AM (#9829410)
> or you rely on some sort of code generation approach.

Exactly.

Re:Golang data structures by fauigerzigerk on Saturday July 04, 2015 @04:07AM (#9829605)
Here's an idea: How about a code generator that interprets special syntax we put into source files? The code generator would run before every compile and its output would be fed straight into the compiler. An apt name might be CPP -- compile preprocessor.

It might be a bit difficult to predict what the input to the compiler actually looks like after CPP has done its job. So we could restrict the kinds of things that CPP can do to make it more predictable. Let's say CPP can only substitute symbols in places where types are asked for...

Re:Golang data structures by enneff on Saturday July 04, 2015 @04:54AM (#9829670)
So do it. If it's a great success, it might end up in the language. (Seriously.)
Re:Golang data structures by jshen on Monday July 06, 2015 @03:49PM (#9841741)
There are languages that have what you want. Why not use them?
Re:Golang data structures by mc808 on Saturday July 04, 2015 @06:12AM (#9829776)
As an outsider who has only tinkered with Go and watched most of Rob Pike's talks, my impression is "C is to Go as Java is to JavaScript" in the sense that both have a thin veneer of a familiar language on top of a fundamentally different, esoteric language. For JavaScript it's Self (prototype inheritance) and for Go it's NewSqueak (CSP).

I don't think Go is really about catering to hordes of cheap junior devs or rebelling against Lisp or Unix, etc. It's (in my interpretation) a way to use channels and goroutines without overwhelming people with academic syntax. As a tool, "the right job" is small and focused on throughput and concurrency - not wiring up webs of generic abstractions. Obviously some people are also finding the language general enough to do the latter, but not without a bit of frustration.

If my understanding is reasonable, people shouldn't be asking "why doesn't Go have generics," but rather "should I be using Go for this? Does this program even have one 'chan' in it?"

Re:Golang data structures by justthistime_ on Saturday July 04, 2015 @12:14PM (#9830559)
> I don't think Go is really about catering to hordes of cheap junior devs

Rob Pike disagrees with you.

Re:Golang data structures by eternalban on Saturday July 04, 2015 @10:07AM (#9830176)
> .. anti-lisp ..

So is Scala. Meaningless.

> .. anti-unix

Actually, the issue is precisely that Rob and team are entirely too comfortable on _nix, so there is a (typical for Go) duality where (L) language is syntactically light and semantically small, (R) *nix is your IDE and piping source through source level transformers are assumed to be 2nd nature to the user.

[p.s.]: (L) is motivated by making another work-day tool for the broadest range of developers and experience levels, and (R) possibly emerged as a de-facto approach given the zippy compiler and source level parsers built into the Std. lib, and comfort at that level is a virtue of a much smaller set of developers that map into (L).

Re:Golang data structures by aikah on Saturday July 04, 2015 @12:33PM (#9830652)
> Go is the anti-lisp / anti-unix of languages

Strange, I thought Go was all about the unix philosophy ?

> It's possible to use these ideas to construct something analogous to type-safe Unix pipes.

https://golang.org/doc/faq

> designed to not give a team of junior devs enough rope to hang themselves

yeah, I thought Google only hires PhDs ... if a noob from a code bootcamp can understand generics within 6 weeks, certainly a guy from a prestigious university hand picked by google can ... please stop being insulting.

Re:Golang data structures by edgyswingset on Saturday July 04, 2015 @01:31AM (#9829348)
> designed to not give a team of junior devs enough rope to hang themselves

I find this to be an utterly silly goal.

Re:Golang data structures by pjmlp on Saturday July 04, 2015 @11:54AM (#9830494)
Not really. Go doesn't fit Google hiring process "we only want CS Phds".

It is also not one language that one can use on the interview exercises.

So given Rob Pike's statement about an easy language for newly hires, one has to wonder where they are coming from.

Re:Golang data structures by aikah on Saturday July 04, 2015 @06:52AM (#9829829)
> they do not believe that generics support as commonly envisioned is in line with go's mission.

More like they can't add generics without breaking the backward compatibility of their mediocre type system.

Re:Golang data structures by danieldk on Saturday July 04, 2015 @07:17AM (#9829852)
More like they can't add generics without breaking the backward compatibility of their mediocre type system.

Reference? Proof?

(Genuinely interested.)

Re:Golang data structures by aikah on Saturday July 04, 2015 @12:34PM (#9830656)
Re:Golang data structures by danieldk on Saturday July 04, 2015 @02:09PM (#9830983)
I don't see anything in Russ Cox's answer that proves your statement. If there is any conclusion to that post, it is 'We can probably do it. But we are not doing it now because we are too afraid that we do it wrong, like Java.'

My problem with the Go team's line of reasoning is that they always cite Java (erasure gives problems) and C++ (too long compile times), but there are many languages that have implemented parametric polymorphism nicely ages ago (C#, ML, Haskell).

Sometimes I wonder if it is the lack of a person like Philip Wadler on the Go team who can hash out how to best fit generics into Go's type system.

Re:Golang data structures by threeseed on Saturday July 04, 2015 @03:18AM (#9829527)
> Go is the anti-lisp / anti-unix of languages; designed to not give a team of junior devs enough rope to hang themselves.

Sounding more like a patronising, holier than thou language to me.

And given that Java implemented generics (sort of) and the world didn't collapse indicates to me junior developers could handle it.