On Tue, 11 Sep 2018, at 3:23 PM, Jeff wrote:
> TLDR; So why contracts and not templates or something else?  Is there
> a benefit to contracts that I don't appreciate (very likely, cause I
> don't understand them)?  Are there issues with a template approach?
> If this has been addressed elsewhere, please provide links.  I'd like
> a better understanding as to why the Go team has chosen to explore
> contracts over other approaches.
I believe that contracts were inspired by C++ Concepts which are
intended to simplify the experience of using C++ Templates, particularly
in the area of developer debugging experience. The main advantage they
have is that instead of a 50 line template compilation error you get a
cleaner "T did not satisfy concept Sortable" from which you can look up
the definition of Sortable.
I think contracts/concepts do a good job of putting a name to a set of
constraints which can then be reused in multiple function declarations.
They keep declarations cleaner and shorter.
The difficult part is making the contracts themselves readable. The Go2
proposal takes the simple approach of using the existing Go type system
on the assumption that Go programmers already understand how those types
work so there is nothing new to learn.
Recent conversations here and around the proposal suggest that the type
system isn't strong or clear enough to convey the kinds of constraints
that we want to use. Personally I am not a fan of having nonsense,
unexecutable code in contract blocks but I do like the general approach.
I wonder whether a DSL is needed to make assertions stronger. Another
alternative could be to borrow more from C++ and make contracts boolean
functions that must return true although this loses the advantages of
just reusing the compiler's type checking since the contracts would have
to be evaluated at compile time too.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to