Skip to content

Instantly share code, notes, and snippets.

@networkimprov
Last active December 4, 2018 19:38
Show Gist options
  • Save networkimprov/7c1f311f26852bc912765e4110af062b to your computer and use it in GitHub Desktop.
Save networkimprov/7c1f311f26852bc912765e4110af062b to your computer and use it in GitHub Desktop.
Please Don't Mangle the Function Signature, re Go2 generics proposal

For gosh sakes, don't make us read code with the scrutiny of a compiler :-) A type declaration after a function name is confusingly similar to an argument list.

Which witch is which?

  • func Stuff(type T Something)(input T) error { ... }
  • func Stuffed(input Somethingelse) error { ... }

C++ style is fine; variations on paren placement can be considered

  • (type T, U) Something // line break or semicolon
    (type V) // more on next line
    func Stuff(input T, more U, other V) error { ... }

And consider simple function aliases for callers

  • func TypedStuff Stuff(TypeA, TypeB, TypeC)
    const TypedStuff = Stuff(TypeA, TypeB, TypeC) // alternatively
    err = TypedStuff(x, y, z)
@kirillx
Copy link

kirillx commented Sep 14, 2018

Absolutely agree, this kills the whole simplicity and readability of the language which made it efficient and so beloved.
If adding generics, then better implement as parametrised packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment