Comment

Comment by tgirod

Interesting read, but I think the first part would benefit from a detour toward interfaces, why they are not good enough to solve the sort problem, and how contracts can help.

IIRC it is along those lines :

You could define a `Lesser` interface with a method `Less(Lesser) bool`, and implement this interface on what you want to sort, but then you would have no way to assert at compile time that x and y are of the same type in `x.Less(y)`.

As I understand them, contracts allow you to assert things like this.

parent tgirod 7 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton