2 ms·
Is anyone else depressed that this article is currently #3 on the front page, and yet his "good idea" (which I think is misguided, but at least is thought-provo
by nostrademons 17y ago
Is anyone else depressed that this article is currently #3 on the front page, and yet his "good idea" (which I think is misguided, but at least is thought-provoking) got zero views? It's like the HN community has collectively proved his point.
Anyway, I'm going to respond to the technical article and not the meta-discussion (I guess these paragraphs would be meta-meta discussion then ;-)):
Lots of programming languages have run up against the problem of combining interfaces, with various solutions. In type theory, this is called "structural subtyping": inferring the type of an object from the methods it must support. Ocaml's object system supports it directly. C++ supports it through "concepts" and "models", which are the foundation of the STL. Python, Ruby, and JavaScript call it "duck typing". Go has it built into its interfaces. Dylan added explicit union and intersection types to the language.
I don't really like the proposed syntax, because it requires that you name all of your concepts. Also, the verbose intersection type-name needs to be carried down to all callers of foo() - so if you had a method bar() that called foo(), it would also need its parameter declared as ReversibleIterator & RemovableIterator. And if you had a method baz() that might call foo() or might do something with a RandomAccessIterator, its type signature would have to be RandomAccessIterator | ReversibleIterator & RemovableIterator. You can see where this is going.
I'd much rather stick to simple structural subtyping, where you can specify (ideally, it'd be compiler-inferred) that iterator must support the previous() and remove() methods, and any type that provides those may be passed in.