Before
func SumProductDiff(i, j int)(s int, p int, d int) {
s = i+j
p = i*j
d = i-j
return
}
After
func SumProductDiff(i, j int)(s int, p int, d int) {
s, p, d = i+j, i*j, i-j
return
}
Before
func SumProductDiff(i int, j int)(s int, p int, d int) {
s, p, d = i+j, i*j, i-j
return
}
After
func SumProductDiff(i, j int)(s, p, d int) {
s, p, d = i+j, i*j, i-j
return
}
- Force using of the factory of structs instead of
new()
package matrix
type matrix struct {
...
}
function NewMatrix(params) *matrix {
m := new(matrix)
// m is initialized
return m
}
Because of the lower case m
of matrix
, we need to use the factory method in another package.
package main
import "matrix"
...
wrong := new(matrix.matrix) // will NOT compile (the struct matrix can't be used directly)
right := matrix.NewMatrix(...) // the ONLY way to instantiate a matrix