3 ms·
Why are these called "contracts"? It's just another generic type mechanism. "Contracts" are generally associated with entry and exit conditions for functions, a
by Animats 7y ago
Why are these called "contracts"? It's just another generic type mechanism. "Contracts" are generally associated with entry and exit conditions for functions, and are not confined to single variables. A real contract looks like:
func foo(a integer, b integer)
{ entry(a>b);
...
}
- sseth 7y agoThe terminology comes from a proposal for C++ which has been under discussion for a long time.
- detaro 7y agoC++ contracts are what Animats describes. Constraints and concepts are more like what's described in the article: https://en.cppreference.com/w/cpp/language/constraints https://en.cppreference.com/w/cpp/language/constraints
- Animats 7y ago"Contract" terminology is from Eiffel, from 1986.[1] [1] https://en.wikipedia.org/wiki/Design_by_contract https://en.wikipedia.org/wiki/Design_by_contract
- Matthias247 7y agoWhy not? They certainly define contracts for the type - at least that's my non-native speaker understanding of the english word. It might seem weird if one used a different programming language which used the term for a slightly different concept - but that doesn't mean Go's usage is bad. The concept is similar to what concepts are in C++ and traits in Rust. And from those terms I actually find contract to be the most understandable for people who are new to these things.
- apta 7y agoThey want to avoid the term "generics" or "traits", same as how they avoided the word "exception" when they implemented "panic". golang likes to reinvent the wheel and call it something else just for the sake of it.
- Animats 7y ago"When I use a word," Humpty Dumpty said, in rather a scornful tone, "it means just what I choose it to mean—neither more nor less." "The question is," said Alice, "whether you can make words mean so many different things." "The question is," said Humpty Dumpty, "which is to be master—that's all."