Y
Hacker News
new
|
ask
|
show
|
jobs
by
Cyph0n
1261 days ago
Why would you have a method that doesn’t touch the receiver? Refactor it into a function.
2 comments
assbuttbuttass
1261 days ago
Dereferencing isn't the only way to touch a pointer:
func (o *myObject) isNil() bool { return o == nil }
link
Cyph0n
1260 days ago
Right, but if you’re doing a nil check, you obviously won’t be worried about nil deferences.
link
remexre
1261 days ago
Either to implement an interface, or because it branches to check if the value is nil before dereferencing it
link
Cyph0n
1260 days ago
Re: the second point, see my other comment.
link