Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: Go 2: Annotations #38672

Closed
joeysudoer opened this issue Apr 26, 2020 · 2 comments
Closed

proposal: Go 2: Annotations #38672

joeysudoer opened this issue Apr 26, 2020 · 2 comments

Comments

@joeysudoer
Copy link

Proposal

It is proposed to add Annotation feature in Go. The reasons are as follows:

  • There is no implementation of the annotation function in Go 1.x. A similar implementation is Struct Tags, but the use scenarios of struct tags are limited and cannot meet some more flexible requirements.

  • Through recent community surveys, it has been known that there are many Go developers who were also Java / Python developers before. The annotation feature in these languages ​​is very powerful. Based on the annotation function, you can flexibly implement some features, such as "dependency injection", which greatly Improve development efficiency.

  • There are some projects on GitHub that indirectly implement similar annotation functions through annotations, such as // @Test, but I think this way looks very weird and not elegant.

Syntax examples

Annotations can refer to the implementation specifications of annotation functions in most programming languages, using the @ symbol as the beginning, followed by the annotation name, and then providing parameters in parentheses after the name, such as

@Get('/user/:id')

The position of the annotation can be above the function, variable and other elements, such as

@Init
func SampleFunc(){

    @Config("sample.valueA")
    var valueA string
    ...

}

Commentary

I know this is a controversial proposal. I have communicated with many Go developers around me. They have shown a conservative attitude towards learning the language features of other languages, but I think that maintaining an open attitude will greatly benefit the development of Go.

@gopherbot gopherbot added this to the Proposal milestone Apr 26, 2020
@josharian
Copy link
Contributor

Please see the discussion in #36669.

@mvdan
Copy link
Member

mvdan commented Apr 26, 2020

Also, please fill https://github.com/golang/proposal/blob/master/go2-language-changes.md as it's a requirement for any proposal that changes the language.

@golang golang locked and limited conversation to collaborators Apr 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants