100-go-mistakes/docs
Philipp Stehle f807004a97
Update #47: change function call order in closure variant
As defer statements are evaluate in reverse order simply wrapping multiple defer in a closure reverses their call order.

Sometimes this might be irrelevant, but as a general advise, I would recommend to swap it.

See https://play.golang.com/p/NTtl-mHnx2x

```golang
package main

import (
	"fmt"
)

func main() {
	direct()
	closure()
}

func direct() {
	defer fmt.Println("direct a")
	defer fmt.Println("direct b")

}

func closure() {
	defer func() {
		fmt.Println("closure a")
		fmt.Println("closure b")
	}()
}

/* Output:
direct b
direct a
closure a
closure b
*/
```

Another difference is behavior on `panic`: When adding two separate `defers` and one panics the other is still executed. This is not the case for a single defered closure. See https://play.golang.com/p/cMYJ7c3pVYJ
2024-08-12 22:30:16 +02:00
..
img Images. 2024-03-05 23:06:05 +01:00
stylesheets New section and content 2023-09-27 17:55:08 +02:00
5-interface-pollution.md Abbreviation, structure 2024-03-08 00:40:56 +01:00
9-generics.md Fix <2> 2024-03-10 16:44:39 +01:00
20-slice.md Polishing 2023-09-29 01:39:48 +02:00
28-maps-memory-leaks.md Merge pull request #69 from aaraney/patch-2 2023-11-28 19:38:27 +01:00
56-concurrency-faster.md Polishing 2023-09-29 01:39:48 +02:00
89-benchmarks.md Polishing 2023-09-29 01:39:48 +02:00
92-false-sharing.md Abbreviation, structure 2024-03-08 00:40:56 +01:00
98-profiling-execution-tracing.md Polishing 2023-09-29 01:39:48 +02:00
book.md Korean cover 2024-03-05 19:49:25 +01:00
chapter-1.md Polishing 2023-09-29 01:39:48 +02:00
CNAME CNAME 2024-02-28 18:52:47 +01:00
external.md Override 2024-03-05 20:15:57 +01:00
index.md Update #47: change function call order in closure variant 2024-08-12 22:30:16 +02:00
ja.md Fixing remaining code annotation 2024-03-10 16:46:00 +01:00
pt-br.md Finished tldr translation 2024-03-18 16:16:07 -03:00
zh.md Update Chinese translation 2024-05-08 00:37:31 +08:00