Reputation
Next privilege 125 Rep.
Vote down
Badges
1 3
Newest
 Enthusiast
Impact
0 people reached

  • 0 posts edited
  • 1 helpful flag
  • 12 votes cast
Sep
29
comment Checking for nil in Go
@MasonWheeler, In Go panic+recover are not at all meant for regular control flow like "true" exceptions in other languages. There are rare cases where using them internal to a package as such make sense (such as the encoding/json package) but that is rare.
Sep
29
comment Checking for nil in Go
@sqroot don't make assumptions for things you don't know. If you don't know let it panic. E.g. bytes's Buffer.Truncatate says "It panics if n is negative or greater than the length of the buffer". If for some reason a caller is passing a raw user provided integer value directly to that function it is up to the caller to check for legal values if they want to return an error instead of letting it panic.
Sep
29
comment Checking for nil in Go
@MasonWheeler "and have it throw an exception" Go doesn't have exceptions. For a programming error a panic is preferable to an error return. If the return is unchecked it's silently ignored, if checked the programmer has to arrange to dump/print sufficient info to find the error... whereas panic dumps out a nice stack trace and a summary of all running goroutines, etc. Makes it real easy to find the place making the incorrect call.
Sep
28
comment Checking for nil in Go
If nil input is a programming error (as it often is) then no, just let the runtime panic when/if it's dereferenced.
Sep
4
comment Golang Testing Process
duplicate of stackoverflow.com/questions/32390582/golang-testing-process
May
13
awarded  Enthusiast
May
2
awarded  Informed
Apr
28
awarded  Citizen Patrol
Mar
27
comment Sets Data Structure in Golang
"works ONLY IF the key are a built-in type" is wrong. type mySet map[IntPoint]bool works perfectly well. All that is required of the key type used in a map is that it has == and !=. Equality of struct types is well defined, your Equals method should be just p1 == p2.
Dec
11
awarded  Supporter