Skip to content

Conversation

@ntakashima
Copy link

No description provided.

Copy link
Owner

@mf-sakura mf-sakura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntakashima
4回目の課題のレビューしました:pray:


numbers := make([]*int, 0, 3)
for i := 0; i < 3; i++ {
i := i
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +27 to +38
keys := make([]int, 0, len(studnetIDMap))
for k := range studnetIDMap {
keys = append(keys, k)
}

for k, v := range studnetIDMap {
sort.Ints(keys)
for _, k := range keys {
// fmt.Printfでフォーマットに従った文字列を標準出力に出せる
fmt.Printf("Name of StudentID:%d is %s\n", k, studnetIDMap[k])
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +21 to +25
fmt.Printf("the address of n is %v\n", &n)
return n + 1
}
func incrementWithPointer(n *int) {
fmt.Printf("the address of n is %v\n", &n)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main関数側のaddressもprintする必要がありました。

}
// fileはCloseする必要がある。
file.Close()
err = file.Close()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これだと他のエラーを上書きしてしまうので、
以下の様にnilで無ければ上書きする実装の方が良いと思います。

if closeErr := file.Close(); closeErr != nil {
	err = closeErr
}

これでもfile.Close()がエラーを出した時は元のエラーを上書きしてしまうので、本当は2つのエラーを結合する処理が必要になります。ややこしいので講義では触れていません。
github.com/pkg/errorsを使った実装例

err = errors.Wrap(err, closeErr.Error())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants