HackerTrans
TopNewTrendsCommentsPastAskShowJobs

rlaitila

no profile record

comments

rlaitila
·4 anni fa·discuss
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.