News for hackers. Stuff that matters.
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.