Reading about arrays and slices in Golang.
Why built-in functions like len
and cap
are used and not similar methods on slice objects?
if cap(slice) == len(slice) {
fmt.Println("slice is full!")
}
vs
if slice.cap() == slice.len() {
fmt.Println("slice is full!")
}
Why polluting the global namespace? Why not using object oriented style?
Also, do such methods exist and can they be used instead of built-in functions?