Sep 2, 2019

[Go][tricks] API compatibility

Reference:
GopherCon 2019: Jonathan Amsterdam - Detecting Incompatible API Changes
https://www.youtube.com/watch?v=JhdL5AkH-AQ
Slides:
https://about.sourcegraph.com/go/gophercon-2019-detecting-incompatible-api-changes
Spec:
https://go.googlesource.com/exp/+/refs/heads/master/apidiff/README.md
Tools binary:
$ go get golang.org/x/exp/cmd/apidiff  # will be replaced by gorelease
Golang /x/tools/go/packages
https://godoc.org/golang.org/x/tools/go/packages
Golang types package
https://golang.org/pkg/go/types/
Golang constant package
https://golang.org/pkg/go/constant/
Golang gcexportdata package
https://godoc.org/golang.org/x/tools/go/gcexportdata


A comparison of two interface values with identical dynamic types causes a run-time panic if values of that type are not comparable.
This behavior applies not only to direct interface value comparisons but also when comparing arrays of interface values or structs with interface-valued fields.

Go v1.15
Use an unexported, zero-width, non-comparable field
(Function values, Slice values and Map values are not comparable
https://golang.org/ref/spec#Comparison_operators ), to
prevent clients from comparing a struct and shrink binary size.
(Using 0 size of array instead of pure Function/Slice/Map which holds a size
of pointer points to memory):
type Point struct {
 _ [0] func()
 X, Y int
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.