As mentioned in my previous question, I’m using a Stack class declared thus:
type Stack []string
func (s Stack) Empty() bool {
return len(s) == 0
}
func (s Stack) Peek() string {
return s[len(s) - 1]
}
func (s *Stack) Push(ss string) {
*s = append(*s, ss)
}
func (s *Stack) Pop() string {
ss := (*s)[len(*s) - 1]
*s = (*s)[:len(*s) - 1]
return ss
}
func (s Stack) Size() int {
return len(s)
}
As you can see 2 of the methods are declared as being bound to (s *Stack). This is how I discovered the code. My question is what advantages if any are there for using 2 of the methods in this way. Would I be better attempting to make all or none of the methods bound to (s *Stack)? I’m experienced in Delphi so I understand all of the heap versus stack issues, but I really need to get my understanding from a Golang perspective up to speed.