News for hackers. Stuff that matters.
Re:Proposal: Go should have generics by lobster_johnson on Friday April 15, 2016 @12:47AM (#11502240)
But a bunch types you do expect to work can: Slices, maps and channels.

  var m map[string]bool
  m["foo"] = 1  // Nil, panic

  var a []string
  a[0] = "x"  // Nil, panic

  var c chan int
  <-c  // Blocks forever
This violates the principle of least surprise. Go has a nicely defined concept of "zero value" (for example, ints are 0 and strings are empty) until you get to these.

The most surprising nil wart, however, is this ugly monster:

    package main

    import "log"

    type Foo interface {
    	Bar()
    }
    type Baz struct{}

    func (b Baz) Bar() {}

    func main() {
    	var a *Baz = nil
    	var b Foo = a
    	fmt.Print(b == nil)  // Prints false!
    }
This happens is because interfaces are indirections. They are implemented as a pointer to a struct containing a type and a pointer to the real value. The interface value can be nil, but so can the internal pointer. They are different things.

I think supporting nils today is unforgivable, but the last one is just mind-boggling. There's no excuse.

Re:Proposal: Go should have generics by JanKanis on Monday April 18, 2016 @08:20AM (#11519301)
I don't think you're right that interfaces are implemented as a pointer to a struct. The struct is inline like any other struct, and it contains a pointer to a type and a pointer to the value, like `([*Baz], nil)` in your example. The problem is that a nil interface in Go is compiled to `(nil, nil)` which is different.

That still makes this inexcusable of course.

Re:Proposal: Go should have generics by lobster_johnson on Monday April 18, 2016 @10:45AM (#11520278)
You're right, it was lurking in the back of my mind that it must be on the stack entirely.
Re:Proposal: Go should have generics by sythe2o0 on Friday April 15, 2016 @10:29AM (#11504559)
I don't think using nil to represent uninitialized data is a major issue-- if it were possible to catch uninitialized but queried variables at compile-time, that could be an improvement, but we want to give the programmer control to declare and initialize variables separately.

I agree the second case is a little silly.

Re:Proposal: Go should have generics by aninhumer on Saturday April 16, 2016 @11:05PM (#11513330)
It's perfectly possible to separate declaration and initialisation without using a null value.