News for hackers. Stuff that matters.
Re:Go 2 Draft Designs by jadbox on Tuesday August 28, 2018 @01:11PM (#17860614)
All I want is typesafe efficient higher order list operations like map, filter, reduce, flatmap, zip, takeUntil, etc. I don't care if Go puts them into the stdlib and only allows these operators to use special internal generics to operate. If Go had a robust higher order std library like this, I would stop asking for generics. Again, must be typesafe and zero overhead.
Re:Go 2 Draft Designs by bradfitz on Tuesday August 28, 2018 @01:24PM (#17860748)
One of the main motivations for adding generics is that we could then put typesafe algorithms and data structures in the standard library.
Re:Go 2 Draft Designs by quotemstr on Tuesday August 28, 2018 @01:27PM (#17860774)
And make the standard library unmagical? One of the things I've always disliked about Go is how stdlib provides magic facilities unavailable to user code.
Re:Go 2 Draft Designs by bradfitz on Tuesday August 28, 2018 @01:36PM (#17860881)
I agree, but there's not much, and it's usually for decent reasons:

* the "time" package hooks into the Go scheduler.

* the "reflect" package needs type information out of the runtime.

* the "net" package hooks into the Go scheduler a bit. But way less than it used to. I think you might even be able to do this all yourself outside of std nowadays.

What else?

Our rough plan going forward is to actually move a bunch of the stdlib elsewhere but ship copies/caches of tagged versions with Go releases. So maybe "encoding/json" is really an alias for "golang.org/std/encoding/json" and Go 1.13.0 ships with version 1.13.0 of golang.org/std/encoding/json. But if you need a fix, feature, or optimization sooner than 6 months when 1.14.0 comes out, you can update earlier.

Re:Go 2 Draft Designs by aleksi on Tuesday August 28, 2018 @01:44PM (#17860956)
My guess that quotemstr meant builtins: append, copy, range "protocol", etc.
Re:Go 2 Draft Designs by TheDong on Tuesday August 28, 2018 @02:08PM (#17861221)
There are many examples of things builtins can do which user-code can't:

1. The constructs like "x <- chan" and "x, ok <- chan" (and map indexing and so on) are only available to builtin types.

It's impossible to write a thing like "x, ok <- chan" where it either panics or doesn't depending on if the caller wanted two or one return values.

2. generic types, like 'map' and 'chan'.

3. 'len' can't be implemented for a user type, e.g. "len(myCustomWorkQueue)" doesn't work.

4. range working without going through weird hoops (like returning a channel and keeping a goroutine around to feed it)

5. Reserving large blocks of memory up front (e.g. as 'make' can do for slices and maps) in an efficient manner (e.g. make(myCustomWorkQueue, 0, 20) doesn't work)

Re:Go 2 Draft Designs by tptacek on Tuesday August 28, 2018 @02:40PM (#17861591)
You're talking about the language. He's talking about the standard library.
Re:Go 2 Draft Designs by quotemstr on Tuesday August 28, 2018 @02:58PM (#17861786)
We're both talking about both. The core of my complaint is that the language privileges parts of the standard library.
Re:Go 2 Draft Designs by TheDong on Tuesday August 28, 2018 @03:12PM (#17861917)
> privileges parts of the standard library

It really doesn't. Maps and channels are not part of the stdlib. They're part of the language, but not the library.

Similarly, range is part of the language, not the stdlib.

If the stdlib was privileged, "container/*" in it would be generic, but it's not.

Re:Go 2 Draft Designs by quotemstr on Tuesday August 28, 2018 @03:19PM (#17861982)
All right, but my point stands. Maps and channels should be part of stdlib, and they should rely on primitives available to user code too.
Re:Go 2 Draft Designs by tptacek on Tuesday August 28, 2018 @03:31PM (#17862092)
Maps and channels are not part of the standard library. How you know that is, you can replace the entire standard library, using none of it, and still be programming in Go with maps and channels.
Re:Go 2 Draft Designs by coldtea on Wednesday August 29, 2018 @07:24AM (#17867351)
Parent wrote "should be" not "are".
Re:Go 2 Draft Designs by thefounder on Tuesday August 28, 2018 @05:11PM (#17862917)
Such primitives would bring a lot of complexity which is something Go tried to avoid.

Consider that make, map, chan etc are just language features/specs just like int64, string, func, main etc

Re:Go 2 Draft Designs by quotemstr on Tuesday August 28, 2018 @07:50PM (#17863964)
Why should string be fundamental?
Re:Go 2 Draft Designs by tptacek on Tuesday August 28, 2018 @09:03PM (#17864341)
Nobody said it "should" be. It simply is, in Go, the language we're discussing. If you nerdsnipe an HN thread with an argument that there's no difference between a language, its runtime, and its standard library, people are going to pile on to point out that's not true.
Re:Go 2 Draft Designs by sagichmal on Tuesday August 28, 2018 @05:51PM (#17863249)
Could, sure. Should? I think you are asserting facts that are not in evidence.
Re:Go 2 Draft Designs by uryga on Wednesday August 29, 2018 @11:50AM (#17869148)
I'm a bit confused, and I'd like to understand your position better. I can see why arrays, structs/tuples, or [tagged] unions are usually primitives – they sort of express different fundamental layouts of data in memory, so they need support from the runtime/compiler. In the case of Go, channels also make sense as a primitive – as I understand it, `select` requires scheduler support.

But higher level data structures like lists, sets, maps etc. are all implemented using those primitives under the hood. So, especially in a "systems language", I would sort of expect them to just be libraries in the stdlib, not language features[1]. But if you think otherwise (or see a gap in my reasoning) I'd love to hear why!

[1] Except maybe some syntactic sugar for list/dict/set literals.

Re:Go 2 Draft Designs by sagichmal on Wednesday August 29, 2018 @04:29PM (#17871677)
"Should" implies some normative assignment of value.

> But higher level data structures like lists, sets, maps etc. are all implemented using those primitives under the hood. So, especially in a "systems language", I would sort of expect them to just be libraries in the stdlib, not language features[1].

Maybe! But if those higher order structures are closer to language features than libraries -- and, specifically to this conversation, if they leverage parts of the runtime that aren't available to mere mortals -- is it a strictly worse outcome? I don't know. Some evidence might suggest yes. But I think it's at best arguable.

Re:Go 2 Draft Designs by uryga on Thursday August 30, 2018 @08:31AM (#17876125)
I think I understand, thanks for explaining.
Re:Go 2 Draft Designs by TheDong on Wednesday August 29, 2018 @12:47PM (#17869691)
> But higher level data structures like lists, sets, maps etc. are all implemented using those primitives under the hood

In Go you don't have generics as a primitive with which to build those things.

As a result, you don't have the building blocks for anyone to build a usable data structure unless it's baked into the core of the language.

Re:Go 2 Draft Designs by uryga on Wednesday August 29, 2018 @01:11PM (#17869901)
I'm aware of that, and I read the generics proposal linked. I commented here because I wanted to respond to this:

> Should [be just libraries]? I think you are asserting facts that are not in evidence.

I tried to describe why I feel that go's collections should be libraries and not builtins, and hopefully understand why GP seemed like they were questioning that idea.

Re:Go 2 Draft Designs by icholy on Tuesday August 28, 2018 @01:35PM (#17860867)
What's magical about the stdlib?
Re:Go 2 Draft Designs by grey-area on Tuesday August 28, 2018 @02:08PM (#17861231)
Maybe they meant the language, which has some generic functions like append or delete - instead of those functions being attached to a data type or accepting any type, they only act on built-in types. I doubt any of that would change though given the stated goal of remaining compatible in most cases.
Re:Go 2 Draft Designs by SamWhited on Wednesday August 29, 2018 @11:17AM (#17868865)
There are a handful of packages (time and some stuff in os for example) that are tied into the runtime and can't be rewritten outside the standard library. It's not a huge amount, and some of it can probably be fixed in the future.
Re:Go 2 Draft Designs by tejasmanohar on Tuesday August 28, 2018 @04:40PM (#17862655)
What if generics were just implemented internally in Go? IMO, there are good use cases, like generic numbers (int32, int64, etc.), list processing, etc. There's already precedence for this with map[A]B, make(), etc.
Re:Go 2 Draft Designs by sdegutis on Tuesday August 28, 2018 @01:32PM (#17860826)
What changed? Why is the Go team finally considering this now, when it has been requested for these exact reasons by many credible developers since Go's beginning?

EDIT: Yes, something has changed. They always said "no, but maybe later" and now it's "ok how about now". That is a big change and I am just asking what's the reason for it.

Re:Go 2 Draft Designs by ianlancetaylor on Tuesday August 28, 2018 @02:41PM (#17861592)
A year ago we said it was time to move toward Go 2: https://blog.golang.org/toward-go2 . This is another step in that direction.
Re:Go 2 Draft Designs by sdegutis on Tuesday August 28, 2018 @06:50PM (#17863627)
Then I'm a year late in asking why the Go team is now deciding to say yes to something they said no to for over half a decade.
Re:Go 2 Draft Designs by ianlancetaylor on Tuesday August 28, 2018 @07:10PM (#17863733)
The blog post explains that.
Re:Go 2 Draft Designs by m_sahaf on Tuesday August 28, 2018 @01:34PM (#17860851)
Nothing changed. It wasn't off the table to begin with. See: https://golang.org/doc/faq#generics
Re:Go 2 Draft Designs by coldtea on Tuesday August 28, 2018 @03:02PM (#17861820)
The question of the parent boils down to "what put it on the menu".

So, yeah, it was always "on the table" in some hazy, we'll see later, way, but not like that.

Re:Go 2 Draft Designs by sagichmal on Tuesday August 28, 2018 @05:53PM (#17863261)
I think a good faith reading of the circumstance would lead one to conclude that the passage of time, and other, higher-priority and lower-cost-of-implementation issues being addressed, have put these issues on the menu.
Re:Go 2 Draft Designs by BurningCycles on Tuesday August 28, 2018 @04:17PM (#17862478)
Likely because they have now figured out implementations of these features which they feel work well with the rest of the language design.
Re:Go 2 Draft Designs by cridenour on Tuesday August 28, 2018 @02:21PM (#17861375)
Because now is later than when they said later?
Re:Go 2 Draft Designs by mikekchar on Wednesday August 29, 2018 @12:07AM (#17865527)
The reason for saying "no, but maybe later" originally was that it was always a desired piece of functionality. I believe the word "inevitable" was even tossed around. The problem was that they didn't like the existing implementations of generics in other languages and also didn't know how they would improve it. I haven't had time to look at the details, so I'm not sure what they actually did, but I think they basically came up with a strategy that they are mostly happy with.

You might ask, why not pick a solution earlier and then improve it over time? However with a popular language it's not that easy. People are writing lots of code. If you start early, you can paint yourself in a corner and end up with a system that you really can't improve very much because it introduces incompatible changes. Note the extremely painful (and drawn out!) incompatible changes with Perl 6 and Python 3. If you make the wrong choice early, you might still take over a decade to find an opportunity to replace it. And since the state of the art in language design moves very slowly, it took a long time before they could see something that they felt they wouldn't regret choosing.

Re:Go 2 Draft Designs by mikekchar on Wednesday August 29, 2018 @02:12AM (#17866055)
I highly recommend reading https://go.googlesource.com/proposal/+/master/design/go2draf...

This is part of the material linked to from this thread. It answers all your questions. You will see that some of the people who are directly replying to you are very much involved in this effort.

Edit: I tried editing the previous message but HN actually automatically made a reply instead....

Re:Go 2 Draft Designs by derefr on Tuesday August 28, 2018 @02:50PM (#17861687)
Adding generics is a major change (e.g. it would restructure the stdlib), and so it would only belong in a major-version bump of the language.
Re:Go 2 Draft Designs by kibwen on Tuesday August 28, 2018 @03:59PM (#17862335)
Though the authors have clarified that the "2" in "Go 2" is just for marketing purposes, and that the actual release would still be "Go 1.x", and shouldn't break any existing code (so it won't restructure the stdlib in any major way, unless they want to do a huge mass-deprecation).
Re:Go 2 Draft Designs by sdegutis on Tuesday August 28, 2018 @04:15PM (#17862454)
So Go is following the exact same path as Java.
Re:Go 2 Draft Designs by qznc on Tuesday August 28, 2018 @05:40PM (#17863142)
Inevitably.

Also inevitably, Java will get value types (structs) at some point.

Just like with Go Generics, people will complain the feature is bolted on. After some time it is just one of the many quirks of a complex language.

I think it was Stroustrup who said: there are two kinds of programming languages, the ones people hate and the ones nobody uses.

Re:Go 2 Draft Designs by pjmlp on Tuesday August 28, 2018 @05:42PM (#17863163)
And Java had quite a few good examples to take on like Modula-3 and Eiffel, but alas they wanted something for average Joe, kind of sounds familiar.
Re:Go 2 Draft Designs by sdegutis on Tuesday August 28, 2018 @05:44PM (#17863179)
The difference is that Go could have learned from Java.
Re:Go 2 Draft Designs by marcus_holmes on Wednesday August 29, 2018 @05:42AM (#17866970)
I think because it would break backward compatability in v1, and not doing that was the Most Important Thing in all 1.xx releases.

v2 is allowed to Break Stuff. So obviously they're going to consider the thing that people have shouted for most in Go... generics and error handling (and package management but they found a way of doing that earlier).

Re:Go 2 Draft Designs by bsder on Tuesday August 28, 2018 @02:54PM (#17861735)
> What changed? Why is the Go team finally considering this now, when it has been requested for these exact reasons by many credible developers since Go's beginning?

Simply, Go has probably accumulated all the developers it is going to accumulate without something drastically changing.

At this point, I can't think of any programmers around me who now want to learn Go.

Re:Go 2 Draft Designs by krylon on Tuesday August 28, 2018 @02:33PM (#17861507)
I basically agree. I still think, while we're at it, making Generics a general feature of the language would probably be easier than adding all kinds of special cases.

But yeah, if Go just added a generic map/filter mechanism (Python's list comprehensions (in turn inherited from Haskell) look very nice), that would cover about %75 of the use cases I want Generics for. Add a generic mechanism to use the range operator with user-defined types, and we're at about 95%.

Re:Go 2 Draft Designs by thiht on Wednesday August 29, 2018 @08:23AM (#17867647)
> Python's list comprehensions (in turn inherited from Haskell) look very nice

Do they? I find them hard to read and hard to chain. I tend to prefer basic map, filter, reduce methods

Re:Go 2 Draft Designs by krylon on Friday August 31, 2018 @05:48PM (#17888800)
Mmmh, that is a good point. I never used nested list comprehensions, to be honest, and I have not used Python in a couple of years. For non-nested cases, they are very nice, though.

OTOH, I never used nested map/remove-if constructs in Lisp, because that, too, can get rather annoying to read.

Re:Go 2 Draft Designs by AndyMcConachie on Tuesday August 28, 2018 @03:21PM (#17862001)
I agree with this sentiment completely. Of course, if the only way to get these wonderful list operations is generics, then I guess I want generics, too.
Re:Go 2 Draft Designs by nemo1618 on Tuesday August 28, 2018 @07:07PM (#17863721)
You might be interested in my project: https://github.com/lukechampine/ply

The idea is that when people say "generics", they usually just mean map/filter/reduce. So ply just bakes those into the language directly instead of adding new generic programming facilities.

Re:Go 2 Draft Designs by ori_b on Tuesday August 28, 2018 @02:19PM (#17861350)
Those are the things that I don't want to see in Go, honestly.
Re:Go 2 Draft Designs by pwm on Tuesday August 28, 2018 @02:27PM (#17861435)
I'm curious: why not?
Re:Go 2 Draft Designs by ori_b on Tuesday August 28, 2018 @05:09PM (#17862906)
Generally, chaining things in the style that encourages that makes it harder to debug the code, harder to step through it in my head or on paper, and harder to compile to performant code. I'd rather see loops.
Re:Go 2 Draft Designs by bschwindHN on Tuesday August 28, 2018 @10:17PM (#17864885)
On the other hand, you're less likely to need to debug those things because they've been implemented once, correctly. A manually-written filter, map, etc. will pretty much always have a higher probability of containing a bug. And in languages that have these features, I've never found it difficult to debug. What issues have you had in the past?
Re:Go 2 Draft Designs by ori_b on Wednesday August 29, 2018 @12:50AM (#17865732)
I've almost never had issues with manually written filters/maps -- at least, not with the iteration itself. On the other hand, having to untangle stack traces of closures of closures that have been passed through closures does slow me down when the function that's being mapped is buggy.
Re:Go 2 Draft Designs by bschwindHN on Wednesday August 29, 2018 @03:52AM (#17866494)
I guess I've never run into issues where a map or filter slowed me down for debugging, most languages will pretty easily show you where the error occurred. And if you're `map`ping and `filter`ing with pure functions, debugging is pretty simple because you just need the input that went into the buggy function. A good compiler will also optimize the closures into something you'd write by hand in Go. Overall I'm glad to see Go get these nice tools for more easily working with collections.
Re:Go 2 Draft Designs by ori_b on Wednesday August 29, 2018 @04:36AM (#17866702)
I've just never run into places where that style improved readability, performance, or debuggability. Outside of the Haskell world, I've usually found myself preferring loops for ease of following the code.
Re:Go 2 Draft Designs by pwm on Wednesday August 29, 2018 @04:46AM (#17866752)
Thanks for your answer. I find it very interesting how different people come to different conclusions about these basic approaches to writing programs. Imho, as always, there's no one true answer and understanding where everyone comes from is very important in understanding this divergence of thought.

In my work I don't think I could live without these higher level abstractions anymore. It enables me to write clear and concise code that helps me keeping accidental complexity under control so that I can focus on the essence of what I'm trying to codify. Performance on the other hand is not a primary concern to me, given it stays above some acceptable threshold.

I appreciate how different tasks would require different approaches. I'm interested in which direction go goes (no pun intended).

Re:Go 2 Draft Designs by platinumrad on Tuesday August 28, 2018 @02:23PM (#17861389)
At that point why not just add generics...
Re:Go 2 Draft Designs by nine_k on Tuesday August 28, 2018 @03:11PM (#17861904)
Lisp tends to build abstractions, too, and it also does that via macros, which are even harder to mentally parse unless you have a habit.

I'd say that to attain simplicity and clarity, you have to limit the use of abstraction. OTOH there's no way to avoid abstraction at all; programming is all about abstraction. If the means of abstraction are not powerful enough, copy-paste programming and boilerplate proliferate, making code less maintainable and harder to understand.

Re:Go 2 Draft Designs by platinumrad on Tuesday August 28, 2018 @03:18PM (#17861976)
In my opinion, implementing these higher order functions with the help of one powerful abstraction (generics) is much simpler than having to deal with a bunch of special cased weaker abstractions (magic map, magic filter, magic reduce, magic...).
Re:Go 2 Draft Designs by gekkonier on Tuesday August 28, 2018 @02:21PM (#17861373)
So you want a Lisp with other syntax, right?
Re:Go 2 Draft Designs by codr4 on Tuesday August 28, 2018 @03:18PM (#17861972)
That's about right. And gradual types, multi methods, generics and tight integration with C++: [0].

Dylan was too long winded for my taste, as are most modern attempts.

[0] https://github.com/codr4life/snabl

Re:Go 2 Draft Designs by coldtea on Tuesday August 28, 2018 @03:03PM (#17861833)
You say it like it's a bad thing.
Re:Go 2 Draft Designs by gekkonier on Tuesday August 28, 2018 @03:25PM (#17862039)
I was just curious, because those functionionality wished is in nearly every list processor, no mather what syntax used. And if not you macro that away, right?