Skip to content

4回目課題実装 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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:

@@ -6,6 +6,7 @@ func main() {

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する必要がありました。

@@ -24,7 +24,7 @@ func CatFile(path string) (err error) {
fmt.Println("Error Handling in defer called.")
}
// 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