Application 2020-09-15

Summary of Go CodeReviewComments

Improve Go code quality with essential code review guidelines: receivers, error handling, goroutines, and naming conventions.

Read in: ja
Summary of Go CodeReviewComments

Overview

I have summarized the points I want to note after reading github.com - CodeReviewComments.

Comment Sentences

Copying

Crypt Rand

Declaring Empty Slices

// Slice of length 0
t := []string{}

Instead, use:

// Nil slice
var t []string

When encoding a JSON object, nil is converted to null, while []string{} is converted to [].

In interface design, it's better not to distinguish between the two, as it may lead to confusing errors.

Don't Panic

Goroutine Lifetimes

Import Blank

Import Dot

package foo_test

import (
    "bar/testutil" // Also imported in foo
    . "foo" // Makes foo_test appear as part of foo
)

Named Result Parameters

Naked Returns

Receiver Type

Guidelines for choosing whether to make a method's receiver a pointer or a value. If unsure, use a pointer.

Cases to Avoid Pointers

Cases to Use Pointers

Useful Test Failures

Messages to convey when a test fails.

References

Tags: Golang Code Review
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles