Skip to content

Instantly share code, notes, and snippets.

View kalexmills's full-sized avatar

Alex Mills kalexmills

View GitHub Profile
@kalexmills
kalexmills / interfaces.md
Last active September 3, 2018 15:34
Replace contracts with built-in interfaces...(and you can name them like this).

Contracts are a creative solution to generics, but they are also unexpected, weird, and possibly unnecessary.

Emily Maier's suggestion that contracts are superfluous is a good one. Interfaces in Go already serve as a kind of contract.

She has observed that, under the current proposal, it would be valid to copy-and-paste the function body into the contract. While the code would compile and presumably run. Go has already made design choices which limit the realm of the possible to keep developers from shooting themselves in the foot.

Contracts in Go only seem to be needed since code needs to assert at compile time that generic types can be used in built-in operations (i.e. that they satisfy a certain operational interface). Rather than introducing a new language construct, it seems more coherent to make these operational interfaces available