awesome-repositories.com
Blog
MCP
awesome-repositories.com

Descoperă cele mai bune repository-uri open source cu căutare AI.

ExploreazăCăutări recomandateAlternative open-sourceSoftware self-hostedBlogHartă site
ProiectServer MCPDespreCum realizăm clasamentulPresă
LegalConfidențialitateTermeni
© 2026 Bringes Technology SRL·VAT RO45896025·hello@awesome-repositories.com
·
teivah avatar

teivah/100-go-mistakes

0
View on GitHub↗
7,915 stele·511 fork-uri·Go·13 vizualizări100go.co↗

100 Go Mistakes

100 Go Mistakes is a reference book and code review companion that catalogues frequent Go programming anti-patterns and provides corrected implementations for each one. It covers a wide range of common pitfalls, from range loop variable capture and interface nil handling to error wrapping and map iteration randomization, helping developers recognize and avoid these issues in their own code.

The project distinguishes itself by offering a structured, example-driven approach to learning idiomatic Go. It covers core design decisions such as when to use pointer versus value receivers, how to apply generics to reduce boilerplate without premature abstraction, and the correct patterns for functional options, type embedding, and consumer-side interface definition. It also addresses concurrency and performance topics, including goroutine scheduling, benchmarking with timer control, false sharing avoidance, and memory leak prevention in slices and maps.

Beyond the core mistake catalogue, the material spans API design, error handling, project organization, and data structure management. It explains how to handle slices and maps correctly—covering capacity management, append side effects, and map memory growth—and provides guidance on string operations, floating-point comparisons, and Unicode handling. The documentation also covers profiling, tracing, and efficient string concatenation with strings.Builder.

Features

  • Common Mistakes and Idioms - The primary purpose: a reference book cataloguing frequent Go mistakes and their corrections.
  • Slice Capacity Pre-allocation - Covers slice capacity management and append behavior without reallocation.
  • Length and Capacity Distinction - Teaches the fundamental distinction between slice length and capacity.
  • Slice Length and Capacity Initialization - Teaches how to initialize slices with explicit length and capacity for performance.
  • Value Comparison - Documents using reflect.DeepEqual for comparing non-comparable types.
  • Suffix and Prefix Trimming - Teaches correct use of TrimSuffix and TrimPrefix for exact substring removal.
  • Slice Mutations by Index - Explains how to correctly mutate slice elements inside Go range loops.
  • Go Type Embedding - Explains Go's type embedding pattern for promoting behaviors while avoiding hidden fields.
  • Type-Embedded Polymorphism - Covers conscious use of Go type embedding to promote behaviors without exposing hidden internals.
  • Visibility-Aware Go Embedding - Teaches embedding types in Go while preventing unintended exposure of internal fields.
  • Emptiness Checks - Teaches checking slice emptiness by length, a fundamental Go idiom for nil and empty slices.
  • Append Side Effect Isolations - Shows how to avoid unintended modifications when appending to shared slices.
  • Map Iteration Order Randomizations - Explains that map iteration order is randomized and not guaranteed.
  • Comparable Type Comparisons - Teaches correct comparison patterns for Go's comparable and non-comparable types.
  • Reflection-Based Comparison - Documents using reflect.DeepEqual for comparing non-comparable types.
  • Go Code Review Companions - Serves as a code review companion cataloguing Go pitfalls with corrected examples.
  • Common Programming Mistakes - Catalogues frequent Go programming mistakes with explanations and code examples.
  • Go Mistake Reference Books - The core identity: a reference book cataloguing common Go mistakes with corrections.
  • Performance Optimization Guides - Provides structured guidance on goroutine scheduling, benchmarking, and concurrent performance optimization.
  • Interface and Generics Design Patterns - Covers consumer-side interface definition and generics usage to reduce boilerplate in Go.
  • Interface Definitions - Teaches the Go idiom of defining interfaces on the consumer side.
  • Map Bucket Memory Leak Prevention - Explains how to prevent memory leaks from Go map buckets that never shrink.
  • Slice Copy Functions - Documents the correct use of Go's copy function for slice duplication.
  • Mutex-Based Resource Synchronizations - Explains mutex usage for synchronizing goroutines accessing shared state.
  • Nil Return Enforcements - Warns against returning nil pointers as interface values, which become non-nil to callers.
  • Explicit Nil Returns from Interfaces - Teaches how to avoid the common mistake of returning a nil pointer that becomes a non-nil interface.
  • Concrete Type Returns - Provides guidance on returning concrete types instead of interfaces to reduce coupling.
  • Loop-Scoped Defer Extraction - Shows how to wrap loop bodies in functions so deferred cleanup runs each iteration.
  • Nil and Empty Slice Distinctions - Explains the crucial difference between nil and empty slices in Go.
  • Explicit Initialization Functions - Advises replacing Go init functions with explicit calls for better testability and error handling.
  • Need-Based Generics Application - Advises applying generics only after a concrete need is identified to avoid over-abstraction.
  • Go Idioms & Patterns - Demonstrates correct Go conventions and practices to replace common anti-patterns.
  • Goroutine-Based Concurrency - Describes using channels for goroutine coordination and data passing.
  • String Iterators - Covers rune-based iteration over strings using range loops and []rune conversion.
  • Receiver Type Selections Based on Usage - Provides criteria for selecting receiver types in Go methods.
  • Integer Overflow Detections - Teaches implementing custom runtime checks for integer overflow, which Go silently wraps.
  • Labeled Scope Breaks - Teaches using labeled break/continue to exit the correct nested loop or switch in Go.
  • Variable Shadowing - Warns against variable shadowing in nested scopes, a common Go bug source.
  • Slice Subsetting - Explains how slicing creates new views sharing the same backing array.
  • Generic Data Structures - Demonstrates using Go generics to reduce boilerplate in data structures and algorithms.
  • Anti-Pattern Corrections - Provides corrected implementations for each documented Go anti-pattern.
  • Go Anti-Pattern Guides - The core identity: a curated catalogue of Go anti-patterns with corrected implementations.
  • Early Return Patterns - Promotes early returns to flatten nested code and improve readability in Go.
  • Generics-Based Duplication Reduction - Shows how generics eliminate repetitive code by separating data types from behavior.
  • Range-Based Loop Iteration - Documents the single-evaluation semantics of range expressions in Go loops.
  • Go Range Loop Pointer Aliasing - Explains the common Go bug where range loop variables share a single address, causing pointer aliasing.
  • Index-Based Mutations - Teaches how to correctly mutate slice elements inside range loops.
  • Struct Mutations by Index - Teaches correct struct mutation inside Go range loops.
  • Interface-Based Decoupling - Advocates defining interfaces on the consumer side to decouple code and enable implementation swapping.
  • Init Function Replacements - Provides explicit guidance on replacing Go init functions with testable alternatives.
  • Go Best Practices Collections - The primary identity: a collection of idiomatic Go patterns and best practices.
  • Error Handling Patterns - Teaches Go's value-based error handling with wrapping, checking, and explicit ignoring.
  • Error Wrapping - Teaches error wrapping with %w to preserve original errors while adding context.
  • Wrapped Error Inspection - Teaches errors.Is and errors.As for inspecting wrapped errors in Go.
  • Wrapped Error Type Inspection - Demonstrates errors.As for type-checking wrapped errors in Go.
  • Functional Options - Documents the functional options pattern for configuring objects with variadic option functions.
  • Judicious Getter and Setter Use - Recommends using getters and setters only when they add value in Go, avoiding boilerplate.
  • Just-in-Time Interface Creation - Advises creating Go interfaces only when a concrete need arises to avoid premature abstraction.
  • Range Loop Variable Captures - Teaches how to avoid the common Go bug of capturing the same loop variable address in closures.
  • Struct Modification by Index - Teaches how to modify struct elements in range loops using index access.
  • Slice Pointer Element Leak Prevention - Explains how to prevent memory leaks from pointer elements in subslices.
  • Substring Backing Array Leak Prevention - Explains how to prevent memory leaks from substrings retaining large backing arrays.
  • Package Scope Naming - Teaches avoiding variable names that conflict with package names in Go.
  • Type Parameter Naming - Advises naming Go return parameters for clarity, especially when multiple parameters share a type.
  • Go Value Comparisons - Explains when to use == versus reflect.DeepEqual for comparing Go values.
  • Suffix Removal Utilities - Teaches correct use of TrimSuffix and TrimPrefix for exact substring removal.
  • Pointer or Value Receiver Selections - Provides guidance on choosing between pointer and value receivers in Go.
  • Project Layouts - Recommends following established Go project layout conventions.
  • Cache Effect Avoidance - Creates fresh data for each benchmark iteration instead of reusing it, so CPU caching does not distort the measured performance.
  • Reader Interface Acceptances - Promotes accepting io.Reader over file paths for flexible data input in Go APIs.
  • Interface-Based Type Behavior Restrictions - Shows how to expose only a subset of methods through an interface to enforce limited access.
  • Getter and Setter Avoidances - Advises against unnecessary getter/setter boilerplate in Go.
  • Getter and Setter Judicious Uses - Advises on the judicious use of getters and setters in Go.
  • Interface-Based Decoupling - Replaces concrete dependencies with interfaces so implementations can be swapped without changing consumers.
  • Parallelism Threshold Settings - Defines a minimum workload size below which goroutine creation overhead outweighs parallel speed gains, preventing slowdowns.
  • Explicit Error Discarding - Demonstrates using the blank identifier to explicitly ignore errors in Go.
  • Deferred Argument Capture - Explains how defer captures arguments at declaration time and how to work around it.
  • Per-Iteration - Shows how to ensure deferred cleanup runs per loop iteration to avoid resource leaks.
  • Per-Iteration Deferred Executions - Shows how to make defer run per loop iteration in Go.
  • String Concatenation Analyzers - Uses strings.Builder with pre-allocation to efficiently join multiple strings, avoiding repeated allocations from the += operator.
  • Efficient String Concatenations with Builders - Uses strings.Builder with preallocation to avoid repeated memory allocation when joining many strings.
  • Behavior Extractions with Generics - Shows how to extract common behaviors like sorting into generic functions.
  • Generic Type Constraints - Restricts type parameters to specific types using interfaces with union operators for compile-time validation.
  • Slice and Map Management Patterns - Provides detailed guidance on slice capacity, append side effects, and map memory growth.
  • Premature Concurrency Avoidances - Evaluates whether a concurrent solution actually outperforms a sequential one by considering workload size, contention, and overhead.
  • False Sharing Avoidances - Prevents performance degradation by ensuring independent variables updated by different goroutines are not placed on the same CPU cache line.
  • Any Type Restrictions - Advises restricting the any type to preserve type safety, matching the any-type restrictions pattern.
  • Named Return Values for Clarity - Recommends naming Go return values for readability.
  • Nil Pointer Return Avoidances - Documents the Go pitfall of returning nil pointers as interface values.
  • Generic Function Definitions - Writes functions that work with any type using type parameters while preserving compile-time type safety.
  • Byte-Based I/O Preferrers - Uses the bytes package to avoid extra conversions when performing I/O operations on byte slices.
  • String-Byte Slice Conversion Analyzers - Uses the bytes package for byte-slice operations instead of converting between string and []byte unnecessarily.
  • Bytes Package Preferrers for Byte Slice Operations - Uses the bytes package instead of converting between []byte and string when performing similar operations.
  • Unnecessary Byte-String Conversion Avoidances - Uses the bytes package instead of converting between []byte and string, as it provides the same operations without allocation overhead.
  • Unrecoverable Error Management - Advises using panic only for programmer errors or unrecoverable dependency failures.
  • Precision-Tolerant Comparisons - Covers epsilon-based floating-point comparison to handle precision errors portably.
  • Deferred Argument Captures - Explains how to avoid immediate argument evaluation in Go defer statements.
  • Early Return Patterns - Advocates early returns and left-aligned happy paths to reduce nested code.
  • Deferred Error Handling - Covers the pattern of explicitly handling or ignoring errors from deferred functions.
  • Map Initializations with Known Sizes - Creates maps with an initial size when the number of entries is known to avoid costly reallocation and rebalancing.
  • Exported Identifier Documentation - Mandates documentation comments on all exported Go identifiers for clarity.
  • Interface-Based Abstractions - Defines interfaces that capture shared methods across types to enable reusable algorithms.
  • Suffix and Prefix Trimmings - Clarifies correct usage of Go's string trimming functions.
  • Memory Leak Prevention - Teaches techniques for preventing memory leaks from slices and maps in Go.
  • Large Slice Memory Leak Avoidances - Copies the needed portion of a large slice to allow the backing array to be garbage collected.
  • Map Memory Leak Preventers - Prevents memory leaks by understanding that Go maps never shrink their bucket array, so deleted elements leave allocated buckets in place.
  • Substring Memory Leak Preventers - Prevents memory leaks by copying a substring or using strings.Clone, because a substring shares the same backing array as the original string.
  • Reflection-Based Comparisons - Explains how to compare non-comparable types using reflect.DeepEqual and custom comparators.
  • Package and Variable Name Collision Avoidances - Advises on avoiding name collisions between packages and variables in Go.
  • Specific Package Namings - Recommends specific, descriptive Go package names over generic ones.
  • Named Result Parameters - Recommends naming Go function result parameters for clarity.
  • Named Result Parameters Sparing Uses - Advises on the cautious use of named return values in Go.
  • Context-Based Organizations - Advises organizing Go projects by business context or technical layer.
  • Purpose-Based Package Namings - Provides guidance on naming packages by their purpose rather than generic categories.
  • Goroutine Scheduling Models - Explains Go's G-M-P goroutine scheduling model for concurrent execution.
  • Single Error Action - Recommends logging or returning an error, but not both, to avoid duplicate handling.
  • Application Performance Profiling - Captures CPU, memory, goroutine, and other runtime profiles via an HTTP endpoint to diagnose performance bottlenecks.
  • Benchmark Result Comparison - Repeats benchmarks multiple times and uses statistical tools to compute stable averages and variation.
  • Timer Reset - Discards elapsed time and memory counters before the measured loop to exclude expensive setup from results.
  • Compiler Optimization Prevention - Assigns benchmark results to global variables to prevent compiler inlining from distorting measurements.
  • Execution Time Benchmarks - Teaches how to measure and report average execution time per operation using Go's benchmark framework.
  • Performance Timers - Covers pausing and resuming benchmark timers to isolate measured function performance.
  • Timer Pause and Resume - Stops and restarts the timer around setup code within each loop iteration to keep measurements focused on the target function.

Istoric stele

Graficul istoricului de stele pentru teivah/100-go-mistakesGraficul istoricului de stele pentru teivah/100-go-mistakes

Căutare AI

Explorează mai multe repository-uri excelente

Descrie ce ai nevoie în limbaj simplu — AI-ul sortează mii de proiecte open source selectate în funcție de relevanță.

Start searching with AI

Alternative open-source pentru 100 Go Mistakes

Proiecte open-source similare, clasificate după numărul de funcționalități comune cu 100 Go Mistakes.
  • a8m/golang-cheat-sheetAvatar a8m

    a8m/golang-cheat-sheet

    8,802Vezi pe GitHub↗

    This project is a Go language cheat sheet and technical reference designed for rapid lookup of syntax patterns and core language features. It serves as a concise programming guide to Go type systems, tokens, and standard programming constructs. The reference covers foundational areas of the language, including concurrency and parallelism through the use of channels and lightweight threads. It also details data modeling using structs and embedding, as well as the language's approach to explicit error handling via return values. Additional guidance is provided on Go application architecture an

    cheat-sheetscheatsheetgo
    Vezi pe GitHub↗8,802
  • xxjwxc/uber_go_guide_cnAvatar xxjwxc

    xxjwxc/uber_go_guide_cn

    8,172Vezi pe GitHub↗

    This project is a translated Go language style guide and programming standard. It provides a collection of coding standards and best practices designed to ensure that Go code remains maintainable, readable, and efficient. The guide focuses on idiomatic patterns for error handling, interface compliance, and memory optimization. It establishes standards for package naming and the use of functional options to maintain backward compatibility in constructors. It covers a broad range of capabilities, including concurrency management for coordinating process lifecycles and preventing resource leaks

    chinesecngo
    Vezi pe GitHub↗8,172
  • ffhelicopter/go42Avatar ffhelicopter

    ffhelicopter/Go42

    5,186Vezi pe GitHub↗

    Go42 is a comprehensive programming language guide and reference for the Go language. It serves as a study of the official language specifications and a collection of design patterns derived from the internal logic and source code of the Go standard library. The project focuses on analyzing official library implementations to demonstrate idiomatic design patterns and core architectural thinking. It maps high-level architectural patterns to specific language features to support the development of scalable and maintainable software. The educational material is organized through case studies an

    Gobookgogo42
    Vezi pe GitHub↗5,186
  • c3lang/c3cAvatar c3lang

    c3lang/c3c

    5,147Vezi pe GitHub↗

    c3c is the compiler for the C3 programming language, transforming source code into executable binaries, static libraries, or dynamic libraries using an LLVM backend. It implements a system based on result-based error handling, scoped memory pooling, and a semantic macro system. The compiler provides first-class support for hardware-backed SIMD vectors that map directly to processor instructions and enables runtime polymorphism through interface-based dynamic dispatch. The project covers a broad set of low-level capabilities, including manual and pooled memory management, inline assembly inte

    C3c3compilerlanguage
    Vezi pe GitHub↗5,147
Vezi toate cele 30 alternative pentru 100 Go Mistakes→

Întrebări frecvente

Ce face teivah/100-go-mistakes?

100 Go Mistakes is a reference book and code review companion that catalogues frequent Go programming anti-patterns and provides corrected implementations for each one. It covers a wide range of common pitfalls, from range loop variable capture and interface nil handling to error wrapping and map iteration randomization, helping developers recognize and avoid these issues in their own code.

Care sunt principalele funcționalități ale teivah/100-go-mistakes?

Principalele funcționalități ale teivah/100-go-mistakes sunt: Common Mistakes and Idioms, Slice Capacity Pre-allocation, Length and Capacity Distinction, Slice Length and Capacity Initialization, Value Comparison, Suffix and Prefix Trimming, Slice Mutations by Index, Go Type Embedding.

Care sunt câteva alternative open-source pentru teivah/100-go-mistakes?

Alternativele open-source pentru teivah/100-go-mistakes includ: a8m/golang-cheat-sheet — This project is a Go language cheat sheet and technical reference designed for rapid lookup of syntax patterns and… xxjwxc/uber_go_guide_cn — This project is a translated Go language style guide and programming standard. It provides a collection of coding… ffhelicopter/go42 — Go42 is a comprehensive programming language guide and reference for the Go language. It serves as a study of the… kaisery/trpl-zh-cn — This project is a localized educational resource for learning the Rust programming language, providing a comprehensive… c3lang/c3c — c3c is the compiler for the C3 programming language, transforming source code into executable binaries, static… rust-lang/book — The Rust Programming Language Book is the official technical guide and educational resource for the Rust language. It…