golang50shades.com
50 Shades of Go: Traps, Gotchas, and Common Mistakes for ...
- Opening Brace Can't Be Placed on a Separate Line - Unused Variables - Unused Imports - Short Variable Declarations Can Be Used Only Inside Functions - Redeclaring Variables Using Short Variable Declarations - Can't Use Short Variable Declarations to Set Field Values - Accidental Variable Shadowing - Can't Use "nil" to Initialize a Variable Without an Explicit Type - Using "nil" Slices and Maps - Map Capacity - Strings Can't Be "nil" - Array Function Arguments - Unexpected Values in Slice and Array "range" Clauses - Slices and Arrays Are One-Dimensional - Accessing Non-Existing Map Keys - Strings Are Immutable - Conversions Between Strings and Byte Slices - Strings and Index Operator - Strings Are Not Always UTF8 Text - String Length - Missing Comma In Multi-Line Slice/Array/Map Literals - log.Fatal and log.Panic Do More Than Log - Built-in Data Structure Operations Are Not Synchronized - Iteration Values For Strings in "range" Clauses - Iterating Through a Map Using a "for range" Clause - Fallthrough Behavior in "switch" Statements - Increments and Decrements - Bitwise NOT Operator - Operator Precedence Differences - Unexported Structure Fields Are Not Encoded - App Exits With Active Goroutines - Sending to an Unbuffered Channel Returns As Soon As the Target Receiver Is Ready - Sending to an Closed Channel Causes a Panic - Using "nil" Channels - Methods with Value Receivers Can't Change the Original Value - Closing HTTP Response Body - Closing HTTP Connections - JSON Encoder Adds a Newline Character - JSON Package Escapes Special HTML Characters in Keys and String Values - Unmarshalling JSON Numbers into Interface Values - JSON String Values Will Not Be Ok with Hex or Other non-UTF8 Escape Sequences - Comparing Structs, Arrays, Slices, and Maps - Recovering From a Panic - Updating and Referencing Item Values in Slice, Array, and Map "for range" Clauses - "Hidden" Data in Slices … - Blocked Goroutines and Resource Leaks - Same Address for Different Zero-sized Variables - The First Use of iota Doesn't Always Start with Zero - Using Pointer Receiver Methods On Value Instances - Updating Map Value Fields - "nil" Interfaces and "nil" Interfaces Values - Stack and Heap Variables - GOMAXPROCS, Concurrency, and Parallelism - Read and Write Operation Reordering - Preemptive Scheduling - Import C and Multiline Import Blocks - No blank lines Between Import C and Cgo Comments - Can't Call C Functions with Variable Arguments … ###### Built-in Data Structure Operations Are Not Synchronized - level: beginner Even though Go has a number of features to support concurrency natively, concurrency safe data collections are not one them :-) It's your responsibility to ensure the data collection updates are atomic. Goroutines and channels are the recommended way to implement those atomic operations, but you can also leverage the "sync" package if it makes sense for your application.
Related Pain Points3件
Inconsistent Data Structure Concurrency Model
7Go's built-in data structures (maps, slices, arrays) are not thread-safe despite the language's strong concurrency support. Developers must manually implement synchronization using goroutines, channels, or the sync package, creating inconsistency in how concurrency is handled.
Numerous Language Gotchas and Edge Cases
6Go has an extensive list of subtle gotchas and counterintuitive behaviors across data structures, concurrency primitives, JSON handling, and more (e.g., nil interfaces vs nil interface values, closed channel panics, unexpected range clause behavior). These are documented in community resources but create a steep learning curve.
Excessive Syntactic Rules and Formatting Constraints
5Go enforces many strict formatting and syntax rules that developers find overly rigid, including constraints on brace placement, variable declarations, and operator usage. These rules limit expressiveness and feel unnecessarily restrictive.