5 Comments
Nov 22, 2023Liked by Phuong Le

Nice list, I've learned a few things, thanks! One question: the link https://medium.com/@func25/go-performance-boosters-the-top-5-tips-and-tricks-you-need-to-know-e5cf6e5bc683 is behind paywall, do you have a copy somewhere else?

Expand full comment
author

Ah yes, I have edited it, here is the story: https://blog.devtrovert.com/p/go-performance-boosters-the-top-5

Expand full comment
Nov 21, 2023Liked by Phuong Le

Very nice, thank you!

For # 1.5, I would just add `t.Helper()` as the first line of `handleDBConnection`.

For # 3, this is also sometimes called the "Builder" pattern, and if any of the steps could cause an error, but you still want the simplicity of chaining, you can add a `Build` or `Do` method at the end of the chain that returns one or more values, including a (potentially "joined") error (typically accumulated during the building of the chain).

I use this builder pattern here, for example: https://github.com/gmlewis/go-bjk/blob/master/examples/bifilar-electromagnet/main.go#L155

Expand full comment
Sep 18, 2023Liked by Phuong Le

Because you have pointer as method receivers:

func (p *Person) AddAge() *Person {

p.Age++

return p

}

func (p *Person) Rename(name string) *Person {

p.Name = name

return p

}:

You can do:

func (p *Person) AddAge() {

p.Age++

}

func (p *Person) Rename(name string) {

p.Name = name

}

See:

https://go.dev/play/p/pSTTBms27ah

Expand full comment
author

No, Marcelloh, the idea behind using method chaining here is to improve code readability and conciseness. With method chaining, you can perform multiple actions on an object in a single line, like this:

```go

p.Rename("Aiden").AddAge().DoA(1).DoB(3)

```

Instead of:

```go

p.Rename("Aiden")

p.AddAge()

p.DoA(1)

p.DoB(3)

```

Expand full comment