--- In [email protected], Steve Searle <[EMAIL PROTECTED]> wrote: > > Around 01:53am on Wednesday, August 06, 2008 (UK time), nimak247 scrawled: > > > Still, I don't understand what 'Asserts' are?? It is tied to an > > expression, I get that, but I guess I am wondering what they are used > > for? Why would you use an assert instead of a try/catch??? > > An assertion is a quick and dirty test for an errors that is used for > debugging/testing only. You assert a condition is true and if it isn't > the program will error. When the release version is compiled the assert > lines are ignored. > > So you could use them in a loop that pops of a stack, asserting that > there is always at least one item on the stack before you pop. During > testing (using the debug version) the assert is always tested. > > When you get to the release version the assert is ignored when the > program is compiled, so that a) its faster, and b) your users don't get > quick and dirty error messages. However they are left in the source > code so can be reused whenever any changes are made in the future. > > It is important that the assert never changes any variables, or the > release version will behave differently. > > assert(x = 1) > > rather than: > > asset(x == 1) > > is the classic example. > > Steve > > -- > > A: Because it messes up the order in which people normally read text. > Q: Why is top-posting a bad thing? > > 01:57:23 up 9 days, 8:29, 1 user, load average: 0.03, 0.12, 0.06 >
Steve, Cool, thanks for explaining the what/why for Asserts! Not so mysterious anymore :O)
