Is there any place I can let others review my Go code?
official_dulin

official_dulin @mrdulin

About: I'm Full Stack Developer, Electrical Engineer and Perfectionist.

Location:
Shanghai
Joined:
Sep 2, 2018

Is there any place I can let others review my Go code?

Publish Date: Sep 9 '20
10 1

Especially concurrency-related code, because they are difficult to test, although you can use go test -race command to detect race condition.

Besides, how to ensure that the goroutine does not leak memory and has the best performance.

Code review generally requires people with more relevant experience, so it seems to be more difficult than solving program problems.

It may take a lot of time for code reviewers. Time is precious. Therefore, without any incentives, I am not sure that my code can be reviewed in time by others and provide good suggestions.

A simple example:

package main

import (
    "fmt"
    "time"
)

func main() {
    var x = 123

    go func() {
        x = 789 // write to x
    }()

    time.Sleep(time.Second)
    fmt.Println(x) // read from x
}
Enter fullscreen mode Exit fullscreen mode

The above code has an issue. We should not use time.Sleep calls for synchronization between goroutines.

But go language does not have such a restriction mechanism, and the correctness of concurrent code seems to be based on experience.

Therefore, although the code passes the go compiler, there is a bug in the code logic.

I only know two places:

But I am looking for other places. Any suggestion? Thanks!

Comments 1 total

Add comment