Hi, We have just released gocontracts 1.3.0. Gocontracts now support arbitrary function preambles and condition initialization.
Function preambles are especially important if you model state transitions: // increaseFirst increases the first element of the array.//// increaseFirst requires:// * len(a) > 0//// increaseFirst preamble:// oldFirst := a[0]//// increaseFirst ensures:// * a[0] == oldFirst + 1func increaseFirst(a []int) { // Pre-condition if !(len(a) > 0) { panic("Violated: len(a) > 0") } // Preamble starts. oldFirst := a[0] // Preamble ends. // Post-condition defer func() { if !(a[0] == oldFirst + 1) { panic("Violated: a[0] == oldFirst + 1") } }() // Implementation a[0]++ } Condition initialization allows you to handle maps, errors *etc.* in your conditions: // SomeFunc does something.//// SomeFunc requires:// * _, ok := someMap[3]; okfunc SomeFunc(someMap map[string]bool) { // Pre-condition if _, ok := someMap[3]; !ok { panic("Violated: _, ok := someMap[3]; ok") } // ... } I hope you find this useful. Any feedback is highly welcome! Cheers, Marko -- 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.