3 ms·
To be fair, the way Go uses interfaces is new.
by sambeau 15y ago
To be fair, the way Go uses interfaces is new.
- pjmlp 15y agoThe only thing new about them is that you don't need to write "implements" or something similar.
- sambeau 15y agoIt is more subtle and powerful than that. By placing the contract at the use of a type with an interface rather than at the declaration of a type you effectively introduce a form of duck typing to a static language. You can write an interface for a type long after the type has been declared (or been declared by someone else). Interfaces can be defined and used without having to go back and change existing code. This is very lightweight.
- pjmlp 15y agoStill, there are a few functional programming languages that offer similar concepts. Scala is one of them, as a few in the ML family.
- he_the_great 15y agoNope, not even. SML apparently did so, and probably others.