-
Go 100 mistakes - #86: Sleeping in unit tests
-
Go - table-driven tests
-
Go - test execution modes
-
Go - the -race flag
-
Go 100 mistakes - #82: Not categorizing tests
-
Go 100 mistakes - #81: Using the default HTTP client and server
-
GO 100 mistakes - #80: Forgetting the return statement after replying to an HTTP request
-
Go 100 mistakes - #79: Not closing transient resources
-
Go 100 mistakes - #78: Common SQL mistakes
-
Go 100 mistakes - #77: Common JSON-handling mistakes
-
Go 100 mistakes - #76: time.After and memory leaks
-
Go 100 mistakes - #74: Copying a sync type
-
Go - pointer in a value copy
-
Go - errgroup
-
Go - sync.Cond
-
Go 100 mistakes - #71: Misusing sync.WaitGroup
-
Go - #70: Using mutexes inaccurately with slices and maps
-
Go 100 mistakes - #69: Creating data races with append
-
Go 100 mistakes - #68: Forgetting about possible side effects with string formatting
-
Go - context keys and values
摘要:IS THERE A WAY TO LIST KEYS IN CONTEXT.CONTEXT? No there is no way to list all the keys of context.Context. Because that type is just an interface. So
阅读全文
-
Go - channel size
-
Go - nil channels
摘要:nil channels always block!
阅读全文
-
Go - notification channels
-
Go 100 mistakes - #64: Expecting deterministic behavior using select and channels
摘要:func main() { messageCh := make(chan int, 10) disconnectCh := make(chan struct{}, 1) for i := 0; i < 10; i++ { messageCh <- i } go func() { for { sele
阅读全文
-
Go 100 mistakes - #62: Starting a goroutine without knowing when to stop it
-
Go - context
摘要:func main() { ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second) defer cancel() go f1(ctx) for i := 0; i < 10; i++ { select { c
阅读全文
-
Go 100 mistakes - #61: Propagating an inappropriate context
-
Go - Zero value of time.Time
-
Go - Contexts
-
Go - Data races vs. race conditions
-
Go - race detector
摘要:Usage To help diagnose such bugs, Go includes a built-in data race detector. To use it, add the -race flag to the go command: $ go test -race mypkg //
阅读全文
-
Chrome - Block advertisement pop-ups
-
Go - when to use channels or mutexes
-
Znote - concurrency and parallelism
-
Go - concurrent processing is not always faster than sequential processing
-
Go - scheduling
-
Go 100 mistakes - #54: Not handling defer errors
-
Go - how to ignore an error purposely
-
Go 100 mistakes - #52: Handling an error twice
-
Go 100 mistakes - #51: Checking an error value inaccurately
-
Go 100 mistakes - #50: Checking an error type inaccurately
-
Go - Type assertions and Type switches
摘要:Type assertions For an expression x of interface type, but not a type parameter, and a type T, the primary expression x.(T) asserts that x is not nil
阅读全文
-
Go - wrap an error
-
Go - panic
-
Go - argument evaluation with defer
-
Go 100 mistakes - #46: Using a filename as a function input
-
Go 100 mistakes - #45: Returning a nil receiver
摘要:We’ve seen in this section that in Go, having a nil receiver is allowed, and an interface converted from a nil pointer isn’t a nil interface. For that
阅读全文
-
Go - named result parameters
摘要:Unintended side effects with named result parameters:
阅读全文
-
Go 100 mistakes - #42: Not knowing which type of receiver to use
-
Go 100 mistakes - #41: Substrings and memory leaks
摘要:We need to keep two things in mind while using the substring operation in Go. First, the interval provided is based on the number of bytes, not the nu
阅读全文
-
Go 100 mistakes: #40: Useless string conversions
-
Go 100 mistakes - #39: Under-optimized string concatenation
-
Go 100 mistakes - #38: Misusing trim functions
-
Go 100 mistakes - #37: Inaccurate string iteration
-
Go - charset and encoding
摘要:We should understand the distinction between a charset and an encoding: A charset, as the name suggests, is a set of characters. For example, the Uni
阅读全文
-
Go 100 mistakes - #35: Using defer inside a loop
摘要:We will implement a function that opens a set of files where the file paths are received via a channel. Hence, we have to iterate over this channel, o
阅读全文
-
Go - break
摘要:A break statement is commonly used to terminate the execution of a loop. When loops are used in conjunction with switch or select, developers frequent
阅读全文
-
Go - range
摘要:A range loop allows iterating over different data structures: String Array Pointer to an array Slice Map Receiving channel In general, range pro
阅读全文
-
Go 100 mistakes - #29: Comparing values incorrectly
摘要:It’s essential to understand how to use == and != to make comparisons effectively. We can use these operators on operands that are comparable: Boolea
阅读全文
-
Go 100 mistakes - #28: Maps and memory leaks
-
Go - map
-
Go 100 mistakes - #26: Slices and memory leaks
摘要:As a rule of thumb, remember that slicing a large slice or array can lead to potential high memory consumption. The remaining space won’t be reclaimed
阅读全文
-
Go 100 mistakes - #25: Unexpected side effects using slice append
-
Go 100 mistakes - #21: Inefficient slice initialization
摘要:Converting one slice type into another is a frequent operation for Go developers. As we have seen, if the length of the future slice is already known,
阅读全文
-
Go - slice
摘要:The slice now references the new backing array. What will happen to the previous backing array? If it’s no longer referenced, it’s eventually freed by
阅读全文
-
Go - floating-point numbers
摘要:Note that there’s an infinite number of real values between math.SmallestNonzeroFloat64 (the float64 minimum) and math.MaxFloat64 (the float64 maximum
阅读全文
-
Go - integer overflow
摘要:func main() { fmt.Printf("math.MaxInt32: %d\n", math.MaxInt32) fmt.Printf("math.MinInt32: %d\n", math.MinInt32) var counter int32 = math.MaxInt32 coun
阅读全文
-
Go 100 mistakes - #16: Not using linters
摘要:A linter is an automatic tool to analyze code and catch errors. To understand why linters are important, let’s take one concrete example. In mistake #
阅读全文
-
Go 100 mistakes - #15: Missing code documentation
摘要:Documentation is an important aspect of coding. It simplifies how clients can consume an API but can also help in maintaining a project. In Go, we sho
阅读全文
-
Go - Project structure
摘要:The Go language maintainer has no strong convention about structuring a project in Go. However, one layout has emerged over the years: project-layout
阅读全文
-
Go 100 mistakes - #11: Not using the functional options pattern
摘要:Here, WithPort returns a closure. A closure is an anonymous function that references variables from outside its body; in this case, the port variable.
阅读全文
-
Go 100 mistakes - #10: Not being aware of the possible problems with type embedding
摘要:Because the mutex is embedded, we can directly access the Lock and Unlock methods from the i receiver.We mentioned that such an example is a wrong usa
阅读全文
-
Go 100 mistakes - #9: Being confused about when to use generics
摘要:Go 1.18 adds generics to the language. In a nutshell, this allows writing code with types that can be specified later and instantiated when needed. On
阅读全文
-
Go - any says nothing
摘要:With Go 1.18, the predeclared type any became an alias for an empty interface; hence, all the interface{} occurrences can be replaced by any. If futur
阅读全文
-
Go 100 mistakes - #7: Returning interfaces
摘要:All in all, in most cases, we shouldn’t return interfaces but concrete implementations. Otherwise, it can make our design more complex due to package
阅读全文
-
Go 100 mistakes - #6: Interface on the producer side
摘要:An interface should live on the consumer side in most cases. However, in particular contexts (for example, when we know—not foresee—that an abstractio
阅读全文
-
Go - 100 mistakes
摘要:Code and project organization: #1: Unintended variable shadowing #2: Unnecessary nested code #3: Misusing init functions #4: Overusing getters and set
阅读全文
-
Go - When to use interfaces?
摘要:Common behavior Decoupling Restricting behavior Common behavior: Restricting behavior:The last use case we will discuss can be pretty counterintuitive
阅读全文
-
VirtualBox - Increase video memory
摘要:zzh@ZZHPC:~ VBoxManagemodifyvmzwin10−−vram256zzh@ZZHPC: VBoxManage modifyvm zwin10 --vram 512 VBoxManage: error: Invalid VRAM size: 512 MB (mu
阅读全文
|