Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 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".



I tend to use Go's panic() in many situations where, in C, I would make assertions.


The point is that they are commonly abused to provide error handling and reporting.


That 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).


But 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.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: