0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Golang Tips

Last updated at Posted at 2024-02-16

Phuong LeによるGolang Tips

Xを徘徊していて有益そうなPostを見かけたのでまとめておく。ちゃんと読んだら別記事で翻訳しながら勉強したいと思っている。

#8, #10, #11, #24 は見つけられなかった。もしご存じの方あればコメントいただけると嬉しいです。

# URL
1 [翻訳転載] Golang Tip #1: 1行のコードで関数の実行時間を計測する
2 [翻訳転載] Golang Tip #2: マルチステージdefer
3 [翻訳転載] Golang Tip #3: パフォーマンスを考慮したスライスの初期化
4 [翻訳転載] Golang Tip #4: 配列をスライスにパースする
5 [翻訳転載] Golang Tip #5: メソッドチェーン
6 [翻訳転載] Golang Tip #6: アンダースコア Import
7 [翻訳転載] Golang Tip #7: 三項演算子
8
9 [翻訳転載] Golang Tip #9: コンパイル時のインターフェイス検証
10
11
12 [翻訳転載] Golang Tip #12: 鍵作成時はmath/randの使用を避ける
13 [翻訳転載] Golang Tip #13: 空スライスとnilスライス
14 [翻訳転載] Golang Tip #14: エラーメッセージを大文字で始めたり区切り記号で終えたりしない
15 When to use Dot (.) Import and Blank (_) Import
16 Don't Return -1 or nil to Indicate Error
17 Understanding "Return fast, return early" to avoid nested code
18 Define interfaces in the consumer package, not the producer
19 Avoid named results unless necessary for documentation
20 Pass values, not pointers
21 [翻訳転載] Golang Tip #21: ポインタレシーバの推奨
22 [翻訳転載] Golang Tip #22: 構造体やオプションパターンを使って関数のシグネチャをシンプルにする
23 Avoid repetition in naming
24
25 Prefer 'chan struct{}' over 'chan bool' for signaling between goroutines
26 Explicitly ignore values with blank identifier (_) instead of silently ignoring them
27 Filter without any allocation
28 Converting multiple if-else statements into switch cases
29 Avoid context.Background(), make your goroutines promisable
30 Keep contexts going with context.WithoutCancel()
31 Loop labels for cleaner breaks and continues
32 Scheduling functions after context cancellation with context.AfterFunc
33 Just... Don’t Panic()
34 Lead with context, end with options, and always close with an error
35 Prefer strconv over fmt for converting to/from string
36 Naming Unexported Global Variables with an Underscore (_) Prefix
37 Using Unexported Empty Struct as Context Key
38 Make your errors clear with fmt.Errorf, don't just leave them bare
39 Avoid defer in loops, or your memory might blow up
40 Handle errors while using defer to prevent silent failures
41 Sort your fields in your struct from largest to smallest
42 Single Touch Error Handling, Less Noise
43 Gracefully Shut Down Your Application
44 Intentionally Stop with Must Functions
45 Always Manage Your Goroutine Lifetime
46 Avoid using break in switch cases, except when paired with labels
47 Table-driven tests, subtests, and parallel tests
48 Avoid Global Variables, Especially Mutable Ones
49 Give the Caller the Right to Make Decisions
50 Make Structs Non-comparable
51 Avoid using init()
52 Adjusting GOMAXPROCS for Containerized Env (Kubernetes, Docker, etc.)
53 Enums start from 1 for categorization and 0 for default cases
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?