Tips and guidance for writing

Reading Note1 General Advice on Technical Writing One of the most crucial aspects of writing a good technical paper is what I call maintaining user state. Like a good operating system, the writer should ensure that the (mental) state of the user (i.e. reader) is kept coherent. Important It means that the paper systematically builds up the reader’s understanding and knowledge of the work, starting from a reasonable initial state. ...

March 31, 2025 · Last updated on August 1, 2025 · 12 min · KKKZOZ

100 Mistakes in Golang: Chapter 8 & 9

55: Mixing up concurrency and parallelism Concurrency enables parallelism. Concurrency provides a structure to solve a problem with parts that may be parallelized. Quote “Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.” ...

March 19, 2025 · Last updated on August 1, 2025 · 4 min · KKKZOZ

100 Mistakes in Golang: Chapter 7

48: Panicking Panicking in Go should be used sparingly. We have seen two prominent cases, one to signal a programmer error and another where our application fails to create a mandatory dependency. 49: Ignoring when to wrap an error In general, the two main use cases for error wrapping are the following: Adding additional context to an error Marking an error as a specific error if err != nil { return fmt.Errorf("bar failed: %w", err) } This code wraps the source error to add additional context without having to create another error type. ...

March 7, 2025 · Last updated on August 1, 2025 · 2 min · KKKZOZ

100 Mistakes in Golang: Chapter 6

42: Not knowing which type of receiver to use In Go, we can attach either a value or a pointer receiver to a method. With a value receiver, Go makes a copy of the value and passes it to the method. Any changes to the object remain local to the method. The original object remains unchanged. On the other hand, with a pointer receiver, Go passes the address of an object to the method. Intrinsically, it remains a copy, but we only copy a pointer, not the object itself (passing by reference doesn’t exist in Go). Any modifications to the receiver are done on the original object. ...

March 4, 2025 · Last updated on August 1, 2025 · 5 min · KKKZOZ

100 Mistakes in Golang: Chapter 5

36: Not understanding the concept of a rune The len built-in function applied on a string doesn’t return the number of characters; it returns the number of bytes. What if we want to get the number of runes in a string, not the number of bytes? How we can do this depends on the encoding. In the previous example, because we assigned a string literal to s, we can use the unicode/utf8 package: ...

March 3, 2025 · Last updated on August 1, 2025 · 3 min · KKKZOZ

100 Mistakes in Golang: Chapter 2

2 Unnecessary nested code 能够提前返回的特殊判定就提前返回 if xxx { // .... return err }else{ // do X } 总是能够写为 if xxx{ return err } // do X Make expected execution flow clear 5 Interface pollution Quote The bigger the interface, the weaker the abstraction. ...

February 20, 2025 · Last updated on August 1, 2025 · 7 min · KKKZOZ

100 Mistakes in Golang: Chapter 3

17 Creating confusion with octal literals In Go, an integer literal starting with 0 is considered an octal integer (base 8). Note the integer literal representations in Golang: Binary - Uses a 0b or 0B prefix (for example, 0b100 is equal to 4 in base 10) Octal - Uses a 0 or 0o prefix (for example, 0o10 is equal 8 in base 10) Hexadecimal - Uses an 0x or 0X prefix (for example, 0xF is equal to 15 in base 10) Imaginary - Uses an i suffix (for example, 3i) 20 Not understanding slice length and capacity In Go, a slice is backed by an array. That means the slice’s data is stored contiguously in an array data structure. A slice also handles the logic of adding an element if the backing array is full or shrinking the backing array if it’s almost empty. ...

February 20, 2025 · Last updated on August 1, 2025 · 12 min · KKKZOZ

100 Mistakes in Golang: Chapter 4

30: Ignoring the fact that elements are copied in range loops type account struct { balance float32 } accounts := []account{ {balance: 100.}, {balance: 200.}, {balance: 300.}, } for _, a := range accounts { a.balance += 1000 } // Output: [{100} {200} {300}] In this example, the range loop does not affect the slice’s content. In Go, everything we assign is a copy: If we assign the result of a function returning a struct, it performs a copy of that struct. If we assign the result of a function returning a pointer, it performs a copy of the memory address (an address is 64 bits long on a 64-bit architecture). Solutions: ...

February 20, 2025 · Last updated on August 1, 2025 · 3 min · KKKZOZ