apache / dubbo-go

Go Implementation For Apache Dubbo .
https://dubbo.apache.org/
Apache License 2.0
4.74k stars 931 forks source link

If we need a code style? #1755

Open pherzheyu opened 2 years ago

pherzheyu commented 2 years ago

What would you like to be added:

Good Code Style.

Why is this needed:

  1. Standardized code promotes teamwork
  2. Standardized code can reduce bug handling
  3. Standardized code can reduce maintenance costs
  4. Standardized code helps code review

How: Although golang does not have a recognized code specification, we can refer to those: https://go.dev/ref/spec https://github.com/golang/go/wiki/CodeReviewComments https://github.com/uber-go/guide/blob/master/style.md

e.g.

var localIp string

func GetLocalIp() string {

}

into

var localIP string

func GetLocalIP() string {

}
type Service struct {
    name     string
    rcvr     reflect.Value
    rcvrType reflect.Type
    methods  map[string]*MethodType
}

into

type Service struct {
    name    string
    rv      reflect.Value // receiveValue
    rt      reflect.Type  // receiveType
    methods map[string]*MethodType
}
duval1024 commented 2 years ago

编码规范考虑划分如下大章节:

justxuewei commented 2 years ago

+1

I think the code specification should be added into https://github.com/apache/dubbo-go/blob/master/CONTRIBUTING.md, and setup the linter on the github action to check if the code meet the specification.

duval1024 commented 2 years ago

I am writing the first edition of the code specification,and try to add it to this issue before this weekend.