什么是"环球之旅"试图说什么?

ube*_*kel 5 go

如果您不知道我的想法,教程中有几点可以让您自己离开而没有线索或链接.所以我对这些的长度感到抱歉:

http://tour.golang.org/#15

Try printing needInt(Big) too
Run Code Online (Sandbox Code Playgroud)

我猜是允许的内容比常量少?


http://tour.golang.org/#21

the { } are required.

(Sound familiar?)
Run Code Online (Sandbox Code Playgroud)

提到了哪种语言?


http://tour.golang.org/#25

(And a type declaration does what you'd expect.)
Run Code Online (Sandbox Code Playgroud)

为什么我们需要单词type和单词struct?我应该期待什么?


http://tour.golang.org/#28

为什么构造函数中隐含零?这听起来像Go的危险设计选择.是否有一个PEP或http://golang.org/doc/go_faq.html以外的任何内容?


http://tour.golang.org/#30

Make?有施工人员吗?new和之间有什么区别make


http://tour.golang.org/#33

delete来自哪里?我没有导入它.


http://tour.golang.org/#36

什么是%v格式化立场?值?


http://tour.golang.org/#47

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
Run Code Online (Sandbox Code Playgroud)

我猜我打破了某种方式....

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)
}
Run Code Online (Sandbox Code Playgroud)

http://tour.golang.org/#59

函数失败时返回错误值?我必须通过错误检查限定每个函数调用?当我编写疯狂的代码时,程序的流程是不间断的?例如Copy(only_backup, elsewhere);Delete(only_backup),复制失败....

他们为什么要那样设计呢?


Den*_*ret 17

试试这个:

func Pic(dx, dy int) [][]uint8 {
    image := make([][]uint8, dy) // dy, not 10
    for x := range image {
        image[x] = make([]uint8, dx) // dx, not 10
        for y := range image[x] {
            image[x][y] = uint8(x*y) //let's try one of the mentioned 
                                             // "interesting functions"
         }    
    }
    return image
}
Run Code Online (Sandbox Code Playgroud)
  • #59:

    语言的设计和约定鼓励您明确地检查它们发生的错误(与其他语言中抛出异常并有时捕获它们的约定不同).在某些情况下,这会使Go代码变得冗长,但幸运的是,您可以使用一些技术来最小化重复的错误处理.

    (引自错误处理和Go)