There are a few points in the tutorial that sort of leave you on your own without a clue or link if you’re not in the know I guess. So I’m sorry about the length of these:
Try printing needInt(Big) too
I’m guessing ints are allowed less bits than constants?
the { } are required.
(Sound familiar?)
Which language is alluded to?
(And a type declaration does what you'd expect.)
Why do we need the word type and the word struct? What was I supposed to expect?
Why implicit zeroes in the constructor? This sounds like a dangerous design choice by Go. Is there a PEP or anything beyond http://golang.org/doc/go_faq.html on this?
Make? Are there constructors? What’s the difference between new and make?
Where did delete come from? I didn’t import it.
What’s the %v formatter stand for? Value?
panic: runtime error: index out of range
goroutine 1 [running]:
tour/pic.Show(0x400c00, 0x40ca61)
go/src/pkg/tour/pic/pic.go:24 +0xd4
main.main()
/tmpfs/gosandbox-15c0e483_5433f2dc_ff6f028f_248fd0a7_d7c2d35b/prog.go:14 +0x25
I guess I broke go somehow….
package main
import "tour/pic"
func Pic(dx, dy int) [][]uint8 {
image := make([][]uint8, 10)
for i := range image {
image[i] = make([]uint8, 10)
}
return image
}
func main() {
pic.Show(Pic)
}
I return error values when a function fails? I have to qualify every single function call with an error check? The flow of the program is uninterrupted when I write crazy code? E.g. Copy(only_backup, elsewhere);Delete(only_backup) and Copy fails….
Why would they design it like that?
#15:
Yes, exactly. According to the spec, “numeric constants represent values of arbitrary precision and do not overflow”, whereas type
inthas either 32 or 64 bits.#21:
None; it’s alluding to #16, which says the same thing, in the same words, about
for-loops.#25 :
a type declaration does what you'd expectis a little unfortunate, I agree (as it assumes too much on what a reader could expect…) but it means you’re defining a struct (with thestructkeyword) and binding the type name “Vertex” to it, with thetype Vertexpart (see http://golang.org/ref/spec#Type_declarations)#28:
the fact that uninitialized structs are zeroed is really really useful in many cases (many standard structs like buffers use it also)
It’s not implicit in the contructor only. Look at this
var i int; fmt.Println(i)This prints out
0. This is similar to something like java where primitive types have an implicit default value. booleans are false, integers are zero, etc. The spec on zero values.#30:
newallocates memory and returns a pointer to it, whilemakeis a special function used only for Slices, maps and channels.See http://golang.org/doc/effective_go.html#allocation_new for a more in-depth explanation of
makevsnew#33:
delete, likeappendorcopyis one of the basic operators of the language. See the full list of them at: http://golang.org/ref/spec#Predeclared_identifiers#36:
Yes,
%vstands for “value”. See http://golang.org/pkg/fmt/#47:
try with this:
#59:
(quoted from Error handling and Go )