3 ms·
There's some really cool ideas in this, and I love how you're straight into the documentation with examples. Great job. I raised my eyebrows at this part thoug
by davedx 3y ago
There's some really cool ideas in this, and I love how you're straight into the documentation with examples. Great job.
I raised my eyebrows at this part though where the type constraints part was being explained:
> Coming from an Object-Oriented background, you may be tempted to compare Contracts to "Interfaces", but you'll find that while they may be used to a similar effect, they are not the same thing. The intention of an "Interface" is to encode subtyping relationships between types, whereas Claro has absolutely no notion of subtyping. [1]
IME with e.g. C#, interfaces are exactly for this kind of thing? Abstract classes and classes are more used for polymorphism?
But I admit it's been a while since I worked with C# and I may be remembering this stuff wrong.
[1] https://docs.clarolang.com/generics/contracts/contracts.generated_docs.html https://docs.clarolang.com/generics/contracts/contracts.gene...
- neonsunset 3y agoC# interface is kind of like Rust's trait except the default passing convention by interface is similar to Box<dyn Trait> whilst passing structs implementing interface via generic arg is identical in the form of Accept<T>(T value) where T : ISomeInterface. Arguably, today the line is somewhat blurred because interfaces can have default member implementations (which are used to extend interfaces without making it a breaking change) but generally you are correct. An abstract class and subclasses that inherit from it signifies what the type is while the interfaces a class or struct implements signify what the type does.
- jasonsteving 3y agoThis section[1] gives a much deeper dive into how I'm thinking about this. [1] https://docs.clarolang.com/generics/contracts/dynamic_dispatch/dynamic_dispatch.generated_docs.html https://docs.clarolang.com/generics/contracts/dynamic_dispat...