Making zero value useful is great idea. It works for slice, mutex and many 
others.

var a []int
a = append(a, 1)
fmt.Println(a)

This works and prints:

[1]

Sadly maps do not seem to have useful zero value. They require call to 
make() or literal to get to useful state.

var a map[int]int
a[1] = 1  // Fails with panic.
// panic: assignment to entry in nil map

Zero value maps are read-only. 

var a map[int]int
fmt.Println(len(a))
// Works and prints 0.

The argument could be that slices are read-only too. Just that "append" is 
special and it makes zero value slices useful.
var a []int
a[0] = 1 // Fails.
// panic: runtime error: index out of range

I am just curious what is the reason behind not making zero maps more 
useful? Is it space?

 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to