News for hackers. Stuff that matters.
Re:What else is in Go 1.11? by DelightOne on Thursday August 16, 2018 @06:26AM (#17773416)
Why isn't Go implementing Optionals like Swift with guard let, if let, etc.?
Re:What else is in Go 1.11? by apta on Thursday August 16, 2018 @06:35AM (#17773465)
Because it would need generics
Re:What else is in Go 1.11? by masklinn on Thursday August 16, 2018 @06:56AM (#17773551)
It could be a special-cased builtin like maps and slices and channels.

AFAIK the reason — much like C# — is their adherence to the concept of ubiquitous defaults / zero values: as far as Go is concerned all types have a zero-value (a non-overridable default value when not explicitly initalised), and as far as its community is concerned zero values are a good thing and must be embraced.

Re:What else is in Go 1.11? by baq on Thursday August 16, 2018 @08:07AM (#17773904)
default zero is good, but default zero pointer... ugh
Re:What else is in Go 1.11? by masklinn on Thursday August 16, 2018 @08:21AM (#17773975)
> default zero is good

Default zero without it being opt-in is terrible.

> but default zero pointer… ugh

That's what ubiquitous default zero gets you.

Re:What else is in Go 1.11? by ainar-g on Thursday August 16, 2018 @06:53AM (#17773538)
No it wouldn't. There are already built-in generic types like map[K]V and slices. If the Go Team wanted, they could easily add built-ins like option[T] and result[T]. But in Go 1.0 they would stand out like a sore thumb, because the stdlib wouldn't use them.

Maybe for Go 2.0.

Re:What else is in Go 1.11? by tmaly on Thursday August 16, 2018 @07:26AM (#17773685)
I would like to see a set library as part of standard library if they are going to do something more on this front.
Re:What else is in Go 1.11? by ainar-g on Friday August 17, 2018 @06:33AM (#17781706)
I would be more radical and add them as a part of the language, the way map is now. AFAIK, Wirthian languages like Pascal and Oberon all have sets as built-ins, with +, -, and * operators defined on them, and Go is heavily inspired by them.
Re:What else is in Go 1.11? by zlynx on Thursday August 16, 2018 @02:38PM (#17777388)
It seems to me that's just a map[set_key]bool
Re:What else is in Go 1.11? by masklinn on Friday August 17, 2018 @07:17AM (#17781900)
1. because you can't build opaque abstractions in Go, you have to wonder if there's a difference between having a true and a false value mapped to a key

2. because sets are significantly less useful without set-operations (intersections, unions, differences) and since go does not have user-defined generics you can't build a generic version of those (

3. because it wastes 1 byte per item (according to the comments in bmap, buckets are implemented column-major

`map[K] struct{}` would fix 3 and the second half of 1 (struct{} is a zero-sized singleton) but is somewhat less ergonomic so the impact of what's left of 1 is worse, and it doesn't solve 2 at all