[英] 50 个 Go 开发者常犯的错误 Go isa simple and fun language, but, like any other language, it has a few gotchas... Many of those gotchas are not entirely Go's fault. Some of these mistakes are natural traps if you ing from another language. Others are due to faulty assumptions and missing details. A lot of these gotchas may seem obvious if you took the time to learn the language reading the official spec, wiki, mailing list discussions, many great posts and presentations by Rob Pike, and the source code. Not everybody starts the same way though and that's OK. If you are new to Go the information here will save you hours debugging your code. Total Beginner: ? 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 ? Accidental Variable Shadowing ? Can't Use "nil" to Initialize a Variable Without an Explicit Type ? 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 So Using "nil" Slices and Maps trings and Byte Slices ? Strings and Index Operator ? Strings Are Not Always UTF8 Text ? String Length ? ma In Multi-Line Slice/Array/Map Literals ? and 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 th
50 个 Go 开发者常犯的错误.doc 来自淘豆网m.daumloan.com转载请标明出处.