Which is the nicer way to initialize a map? [duplicate]

One allows you to initialize capacity, one allows you to initialize values:

// Initializes a map with space for 15 items before reallocation
m := make(map[string]int32, 15)

vs

// Initializes a map with an entry relating the name "bob" to the number 5
m := map[string]int{"bob": 5} 

For an empty map with capacity 0, they’re the same and it’s just preference.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)