Quantcast
Channel: cc :: somkiat
Viewing all articles
Browse latest Browse all 1997

หนังสือน่าสนใจ 100 Go Mistakes

$
0
0

วันนี้เห็นหนังสือที่น่าสนใจคือ 100 Go Mistakes: How to Avoid Them
ทาง email โดยช่วงนี้ลด 40% อีกด้วย
ว่าด้วย 100 เรื่องที่มักจะใช้งานผิดพลาดในภาษา Go
เพื่อช่วยให้ Go Developer ได้เรียนรู้
เพื่อรู้และเข้าใจ รวมทั้งหลีกเลี่ยงความผิดพลาดที่อาจะเกิดขึ้นได้

ผู้เขียนหนังสือเล่มนี้ เริ่มจากการเขียนบทความเรื่อง
The Top 10 Most Common Mistakes I’ve Seen in Go Projects

เนื้อหาในหนังสือเล่มนี้ประกอบไปด้วย

Basics:

  • Unintended variable shadowing
  • Ignoring logging side effects
  • Comparing values incorrectly
  • JSON handling mistakes
  • Formatting network addresses for IPv4 solely
  • Handling enums incorrectly
  • Not using defer
  • Ignoring how defer arguments and receivers are evaluated
  • Not closing resources
  • Creating confusion with octal literals
  • Neglecting integer overflows
  • Not understanding floating-points
  • Not using linters

Code organization:

  • Writing nested code
  • Misusing init functions
  • Always using getters and setters
  • Interface pollution
  • Interface on producer-side
  • Returning interfaces
  • interface{} says nothing
  • Not using the functional options pattern
  • Project misorganization
  • Creating utility packages
  • Ignoring package name collisions
  • Missing code documentation

Data structures:

  • Not understanding slice length and capacity
  • Inaccurate slice initialization
  • Creating conflicts using slice append
  • Not making slice copy correctly
  • Slice and memory leaks
  • Being confused about nil vs. empty slice
  • Not properly checking if a slice is empty
  • Inaccurate map initialization

Control structures:

  • Ignoring that elements are copied in range loops
  • Ignoring how arguments are evaluated in range loops
  • Ignoring the impacts of using element pointers in range loops
  • Making wrong assumptions during map iterations
  • Ignoring how the break statement work
  • Using defer inside a loop
  • Forgetting about the switch fall through behavior

String:

  • Not understanding the concept of rune
  • Inaccurate string iteration
  • Misusing trim functions
  • Under-optimized strings concatenation
  • Useless string conversion
  • Substring and memory leaks

Functions and methods:

  • Not knowing which type of receiver to use
  • Not using named result parameters
  • Unintended side-effects with named result parameters
  • Returning a nil receiver
  • Using a filename as a function input

Error management:

  • Panicking
  • Ignoring when to wrap an error
  • Comparing an error type inefficiently
  • Comparing an error value inefficiently
  • Handling an error twice
  • Ignoring an error
  • Not handling defer errors

Concurrency:

  • Mixing concurrency and parallelism
  • Concurrency isn’t always faster
  • Misunderstanding Go contexts
  • Not understanding what a race condition is
  • Append is not always race free
  • Goroutines and loop variables
  • Channel receive/send and context
  • Not using directional channels
  • Not using notification channels
  • Closing channels inaccurately
  • Buffered channel capacity and magic number
  • Not using nil channels
  • Passing a struct containing a sync field
  • Exporting concurrency primitives
  • Not using sync.RWMutex
  • Misusing sync.WaitGroup
  • Forgetting about sync.Cond
  • Not using errgroup package
  • Not using runtime.NumCPU()
  • time.After and memory leak
  • Ignoring false sharing

Testing:

  • Forgetting to fail a test
  • Not using table-driven tests
  • Not using test build flags
  • Not using the race option
  • Not checking goroutines leaks
  • Writing inaccurate benchmarks

Optimization:

  • Byte slice and map key
  • Pointers everywhere
  • Expecting that a pointer address is constant
  • Structure alignment
  • Inlining

Production:

  • Using the default http client and server
  • Go and Docker
  • Not exposing a pprof endpoint
  • Generating random numbers in security-sensitive applications

ลองหาอ่านกันดูครับ
น่าจะมีประโยชน์สำหรับการพัฒนาระบบด้วยภาษา Go


Viewing all articles
Browse latest Browse all 1997

Trending Articles