Asserting your way in ActionScript and Objective-C

We often get asked “what’s with all those assert statements in your code”?

This concept was hammered in my head when I was a junior programmer, so I
feel kind of old every time I am asked to explain it. But hey…

An assert is usually defined as a “debug-only macro that aborts execution if its argument is false”. (See Steve Maguire’s Writing Solid Code) In other languages, like ActionScript, where you don’t have macros, you can use other techniques to achieve the same effect. The idea is that you use an assert as a diagnostic tool to help you narrow down runtime problems in debug builds. If a function asserts that the arguments passed to it are valid (non-NULL, within an expected range or whatever else constitutes valid in the context of the function), you will know as soon as something dodgy comes in, because your app will crash inside that function in debug. Without the assert the function may not crash, but instead pass the bad data down the line, making the chain of responsibility, and thus the time it takes you to get to the source of the bad data, longer.


Warning: count(): Parameter must be an array or an object that implements Countable in /home/easyna6/public_html/easynativeextensions_wp/wp-includes/class-wp-comment-query.php on line 399

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">