Skip to content

proposal: Go 2: Function alias #58897

Closed as not planned
Closed as not planned
@xbt573

Description

@xbt573

Author background

  • Would you consider yourself a novice, intermediate, or experienced Go programmer?
    Intermediate
  • What other languages do you have experience with?
    Python, C#, JS/TS, Bash

Related proposals

  • Has this idea, or one like it, been proposed before?
    Probably not
  • Does this affect error handling?
    No
  • Is this about generics?
    No

Proposal

  • What is the proposed change?
    This proposal adds something like type aliases, but for functions
  • Who does this proposal help, and why?
    If we take code like this:
type SomeFunctionType func(string) string

func CreateSomeFunction() SomeFunctionType {
    return func(s string) string {
        return s
    }
}

var SomeFunction = CreateSomeFunction()

And then check documentation for SomeFunction, it will show:

var SomeFunction package.SomeFunctionType

It is very disappointing at first time

  • Please describe as precisely as possible the change to the language.
    This proposal adds new syntax:
func X=Y

If Y doc is:

func Y(str string) string

Then, X doc will be:

func X(str string) string
  • What would change in the language spec?
    New syntax, new chapter about function alias
  • Please also describe the change informally, as in a class teaching Go.
    Function alias helps create function type variables documentation easier
  • Is this change backward compatible?
    Yes
  • Orthogonality: how does this change interact or overlap with existing features?
    It doesn't
  • Is the goal of this change a performance improvement?
    No

Costs

  • Would this change make Go easier or harder to learn, and why?
    It can make Go a little bit harder to learn, but it will make documentation better in some cases
  • What is the cost of this proposal? (Every language change has a cost).
    New syntax realization
  • How many tools (such as vet, gopls, gofmt, goimports, etc.) would be affected?
    gopls, gofmt (maybe)
  • What is the compile time cost?
    Translating functions
  • What is the run time cost?
    None
  • Can you describe a possible implementation?
    No
  • Do you have a prototype? (This is not required.)
    No

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions