dubbo-go icon indicating copy to clipboard operation
dubbo-go copied to clipboard

If we need a code style?

Open pherzheyu opened this issue 3 years ago • 3 comments

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
}

pherzheyu avatar Feb 17 '22 05:02 pherzheyu

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

  • 命名
    • 本地变量命名
    • 全局变量命名
    • 全局常量命名
    • 结构体命名
    • 函数命名
  • 注释
    • 函数注释
    • 结构体注释
  • 控制结构
  • 编码风格
    • 代码对齐
  • ...

duval1024 avatar Feb 17 '22 06:02 duval1024

+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.

justxuewei avatar Feb 17 '22 09:02 justxuewei

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

duval1024 avatar Feb 18 '22 06:02 duval1024