|
|
|
|
|
by sauerbraten
2126 days ago
|
|
I checked out the example code for arrays (https://github.com/betty200744/ultimate-go/blob/3de8a053d9f7...) and noticed that OP seems to misunderstand a few things about Go arrays: - the cheat sheet differentiates between 'declaring' and 'declaring and initializing', but in Go there are no uninitialized arrays (or slices)
- a lot of times in this file, a slice is created instead of an array (lines 18, 21, 25, 31)
- arrays in Go don't really have a capacity (it's always the same as the array's length)
- the built-ins append and copy as well as the sort functions don't accept arrays (I assume this is why slices are created?) |
|
This is a little murky and misleading. In Go, you can actually save memory by 'declaring' only. For example, if you do var x []string, and never use x, it never actually uses memory. Whereas x := []string{} does. The JSON encoder treats the two differently, as well.