4 ms·
That is what I was wondering: http://golang.org/doc/faq#assertions http://golang.org/doc/faq#assertions > Why does Go not have assertions? > Go doesn't provi
by baby 12y ago
That is what I was wondering: http://golang.org/doc/faq#assertions http://golang.org/doc/faq#assertions
> Why does Go not have assertions?
> Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error handling and reporting. Proper error handling means that servers continue operation after non-fatal errors instead of crashing. Proper error reporting means that errors are direct and to the point, saving the programmer from interpreting a large crash trace. Precise errors are particularly important when the programmer seeing the errors is not familiar with the code.
> We understand that this is a point of contention. There are many things in the Go language and libraries that differ from modern practices, simply because we feel it's sometimes worth trying a different approach.
I was wondering how the "go test" function was working as well, here is a start of an answer: http://golang.org/doc/faq#How_do_I_write_a_unit_test http://golang.org/doc/faq#How_do_I_write_a_unit_test
- ExpiredLink 12y ago> programmers use them as a crutch to avoid thinking about proper error handling and reporting Funny, because asserts in C are used to find bugs but not for "error handling and reporting".
- dasmithii 12y agoI tend to use Go's panic() in many situations where, in C, I would make assertions.
- amscanne 12y agoThe point is that they are commonly abused to provide error handling and reporting.
- sfk 12y agoThat is what the Go developers claim. I don't see this abuse very often in C, either. If a speed sensitive function in C is documented to work for integers in the range 0 < x < 256, then it makes sense to put in an assert() as a courtesy to the users of the function. It does not make sense in every situation to do a range check and return an error, or worse, "panic" (the latter didn't work for the Ariane 5).
- amscanne 12y agoBut you're giving an example where you think an explicit panic is justified. Losing asserts doesn't eliminate either option. It simply requires you to have exicit error handling or a panic. This is the point.