Common practice might be to put asserts in code to check input parameters, data integrity, and such, during app development.
I test my apps, BUT, given that I’m not Knuth (and he writes $1 checks), and I can’t afford to employ a large team of full-time QA people as do some medical and space systems software companies, I assume that all my apps will always have plenty of bugs that have never yet been seen during testing or QA. Assuming otherwise seems quite intellectually dishonest. So after testing an app (and obviously removing all bugs causing any previously seen ASSERT failures) and getting the app ready to ship to Apple, what should be done with all the ASSERT checks in the Release/Distribution build? Leave or no-op?
Here’s one rationale for leaving them in: If an app acts wonky for some users, the app might get rated by those users as 1-Star without anyone ever telling the developer why in sufficient detail. But if the app crashes from an ASSERT failure, the app might still get rated 1-Star, but the developer could potentially get some crash dumps, indirectly via iTunes and iTunes Connect if enough users opts in, to figure out what is going wrong. And if the app gets rejected by Apple due to a brand new ASSERT crash, that will prevent a bad version of the app from ever getting onto one’s customer’s devices.
Leave them in for exactly the reasons you specify, but also because in certain cases they act as comments (especially where types are concerned in Objective-C). And do not worry about the performance hit unless it becomes a problem or you know you’re in a performance critical situation and a particular assert is going to be run hundreds or thousands of times on the main run-loop.
Can’t resist mentioning this article on asserts vs. NSAssert.
Personally, I start to remove the ones that I’ve put in for debugging purposes, but if you use asserts to check data integrity, parameters, resource dependencies and other related things — arguably, you could throw Exceptions yourself instead, which might be wiser — then I would leave them in.
Note: A further point is that just removing asserts is utterly stupid, since your app will either crash or be in an inconsistent state, both of which are worse than crashing in a way that you can recognize from the crash logs (so leave the asserts in). Replace asserts with
ifstatements, on the other hand, could be a good thing.