When to use make vs inline slice initializer?

Viewed 423

Consider the following two snippets of code:

// Declaring the values inline.
os_list := []string{"Mac OSX", "Linux", "Windows 7"}
fmt.Println(os_list)

// Appending them to an empty slice.
os_list_two := make([]string, 3)
os_list_two = append(os_list_two, "Mac OSX", "Linux", "Windows 7")
fmt.Println(os_list_two)

When should we use one or the other?

2 Answers
Related