Kindle Notes & Highlights
by
Ivo Balbaert
Started reading
February 18, 2020
go doc package/subpackage to get the documentation for subpackage in package, ex: go doc container/list
go install (formerly goinstall) is the go-package install tool; much like rubygems for the Ruby language. It is meant for installing go packages outside of the standard
2 Go functions Random() and Seed(), which call the equivalent C functions C.random() and C.srandom(): Listing 3.2—c1.go: package rand
} In fact even the simple Print-functions of fmt (see § 4.4.3) also return 2 values: count, err := fmt.Println(x) // number of bytes printed, nil or 0, error When printing to the console these are not checked, but when printing to files, network connections, etc. the error value should always be checked. (see also Exercise 6.1b)
When a function is invoked copies of the arguments are made and these are then passed to the called function.
A function call can have another function call as its argument, provided that this function has the same number and types of arguments in the correct order that the first function needs, e.g.: Suppose f1 needs 3 arguments f1(a, b, c int), and f2 returns 3 arguments: f2(a, b int) (int, int, int), then this can be a call to f1: f1(f2(a, b))
Reference types like slices (ch 7), maps (ch 8), interfaces (ch 10) and channels (ch 13) are pass by reference by default (even though the pointer is not directly visible in the code).
Named variables used as result parameters are automatically initialized to their zero-value, and once they receive their value, a simple (empty) return statement is sufficient;
If the last parameter of a function is followed by …type, this indicates that the function can deal with a variable number of parameters of that type, possibly also 0: a so called variadic function: func myFunc(a, b, arg …int) {} The function receives in effect a slice of the type (see chapter 7), which can be looped through with the for _, v := range construct
If in a variadic parameter the type is not specified, it defaults to the empty interface { } which can stand for any other type