Panics should never happen in a library
pcman312 opened this issue · comments
Panicking in a library is an anti-pattern in Go. It results in indeterministic and unpredictable code. The caller has no idea when a library is going to panic unless they are experts in the library's codebase.
Currently, this is being done in several places:
Line 70 in bbe6d2a
Line 163 in bbe6d2a
I believe a better option would be to allow for any size in the New()
function, but then checking it in the Build()
and returning an error. This makes it more idiomatic and removes the possibility that the caller's program crashes unexpectedly because of a bad input.