golang / tour

[mirror] A Tour of Go
BSD 3-Clause "New" or "Revised" License
1.54k stars 521 forks source link

tour: [REPLACE WITH SHORT DESCRIPTION] #489

Open jamesray1 opened 6 years ago

jamesray1 commented 6 years ago

Context: http://127.0.0.1:3999/basics/7

package main

import "fmt"

func split(sum int) (x, y int) {
    x = sum * 4 / 9
    y = sum - x
    return
}

func main() {
    fmt.Println(split(17))
}

In the tour, when you run this, it returns 7 10.

However, 17*4/9 is not equal to 7.

jamesray1 commented 6 years ago

Ah, but they are integers, so it rounds 17*4/9 = 7 + 5/9 down to 7 (discarding the extra fraction).

jamesray1 commented 6 years ago

You should add a note about that for newcomers.

jamesray1 commented 6 years ago

Then on the next page:

package main

import "fmt"

var c, python, java bool

func main() {
    var i int
    fmt.Println(i, c, python, java)
}

You should explain for newcomers that vars are instantiated to the zero state for their type (e.g. 0, false) when declared without explicit instantiation.

jamesray1 commented 6 years ago

Ah I see that the latter is done in basics/12, you could add a cross-reference to that.