I'm currently working my way through the excellent Tour of Go. I finished one of the exercises (#45) with the following solution:
func Pic(dx, dy int) [][]uint8 {
pic := make([][]uint8, dy) /* type declaration */
for i := range pic {
pic[i] = make([]uint8, dx) /* again the type? */
for j := range pic[i] {
pic[i][j] = uint8((i+j)/2)
}
}
return pic
}
I don't understand why I have to use a make
statement with the uint8
type twice (see comments in snippet). That seems redundant but I can't figure out how to do it in an other way.