I'm a java developer and I am learning Go. I'm writing simple 'pop' operation for a LIFO stack. The question is with the return value when there are no values in the stack. In java, I'm able to return a wrapper(Integer) in the positive case and null when there are no values. It's natural from my perspective.
How can I do something similar in Go? Are there any struct wrappers for primitives? Do I need to return two values(the second will indicate error code)? Or do I need to throw an exception?
Here's how it looks for now:
func (s *stack) Pop() (int, bool) {
if s.size == 0 {
return 0, true
}
s.size--
val := s.stack[s.size]
return val, false
}
Is it good style?