|
|
|
|
|
by rlaitila
1308 days ago
|
|
I think this article conflates interface and specification: interface: describe required inputs in exchange for perceived outputs. No more, no less. Environmental concerns or invariants are the responsibility of the conformer. Interfaces communicate a boundary of incomplete information while allowing interoperability in face of incomplete information. Interfaces are explicitly inclusive. specification: describe the exact inputs and exact outputs while describing all invariants. specifications communicate the exact conditions in which inputs/outputs can be exchanged and all possible (known) invariants. Specifications are explicitly exclusive. Per the article: const Animal = union(enum){
cat: Cat,
dog: Dog,
Is a specification not an interface. At no point can I conform to this "interface" without the "interface" knowing of my existence. Animal must know about all possible invarients to operate correctly, such that it is a specification.If I want to join two pieces of pipe together, the interface would be the inner diameter say 1". The specification of some use case would say only 1" inner diameter pipes can be joined with other 1" inner diameter pipes that have an outer-diameter of at minimum 1.25" due to "pressure constraints". If I choose a pipe that has the same inner diameter but different outer diameter, I've conformed the interface but failed the specification. The rest of the article seems to try and affirm the interface argument by jumping into syntax and compilation arguments. I fail to see how this has anything to do with Zig or abstract ideas of interfaces. |
|
For the purpose of that post I'm loosely defining interfaces as "runtime polymorphism". The article "jumps" into syntax because that's what I'm trying to show, there really is no argument that I'm making about the abstract idea of an interface.
As stated at the top of the article (and in other comments here), if you want vtable style interfaces, you can have vtable style interfaces: just make a vtable and use it, the language won't stop you :^)
> I fail to see how this has anything to do with Zig or abstract ideas of interfaces.
Yep, that's because the article was never about abstract ideas of interfaces. It does pertain Zig specifically because it shows off a new language feature: `inline else`.