Re: Proper Use of Assert and Enforce

2016-02-05 Thread bachmeier via Digitalmars-d-learn
On Friday, 5 February 2016 at 09:50:43 UTC, Suliman wrote: Will asserts stay after compilation in release mode? No. The only assert that remains in release mode is assert(false) or assert(0) as a way to identify that you've reached a piece of code that shouldn't be executed.

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 5 February 2016 at 08:45:00 UTC, Minas Mina wrote: Use assertions when a variable's value should not depend on external factors. For example, let's say you want to write a square root function. The input must be >= 0, and because this depends on external factors (e.g. user input), yo

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Suliman via Digitalmars-d-learn
On Friday, 5 February 2016 at 08:45:00 UTC, Minas Mina wrote: On Wednesday, 14 March 2012 at 05:44:24 UTC, Chris Pons wrote: I'm new, and trying to incorporate assert and enforce into my program properly. My question revolves around, the fact that assert is only evaluated when using the debug

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Minas Mina via Digitalmars-d-learn
On Wednesday, 14 March 2012 at 05:44:24 UTC, Chris Pons wrote: I'm new, and trying to incorporate assert and enforce into my program properly. My question revolves around, the fact that assert is only evaluated when using the debug switch. I read that assert throws a more serious exception th

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 02/05/2016 12:01 AM, Suliman wrote: It is purely a way to make throwing an exception use a syntax similar to assert and save a line of code. if(!condition) throw new Exception(msg); becomes enforce(condition, msg); So enforce is just macros on top of: if(!condition) throw new Ex

Re: Proper Use of Assert and Enforce

2016-02-05 Thread Suliman via Digitalmars-d-learn
It is purely a way to make throwing an exception use a syntax similar to assert and save a line of code. if(!condition) throw new Exception(msg); becomes enforce(condition, msg); So enforce is just macros on top of: if(!condition) throw new Exception(msg); ?

Re: Proper Use of Assert and Enforce

2012-03-14 Thread Chris Pons
Thank you for the valuable information! The difference between assert and enforce is now clearer in my mind. Also, that's a great trick with enforce. On Thursday, 15 March 2012 at 01:08:02 UTC, Jonathan M Davis wrote: On Wednesday, March 14, 2012 20:15:16 Spacen Jasset wrote: Is enforce then

Re: Proper Use of Assert and Enforce

2012-03-14 Thread Jonathan M Davis
On Wednesday, March 14, 2012 20:15:16 Spacen Jasset wrote: > Is enforce then a way of generating exceptions in an easier way rather > than using some sort of "if (failure) throw" syntax? In other words, I > assume it's a mechanism to help you use exceptions, and not some new > semantic. It is pure

Re: Proper Use of Assert and Enforce

2012-03-14 Thread Spacen Jasset
On 14/03/2012 09:59, Dmitry Olshansky wrote: ... To make it real simple: - assert on stuff you know has to be true regardless of circumstances and not dependent on any possible external factors. - enforce on stuff that must be true, but in general can fail like "file not found", etc. and/or depe

Re: Proper Use of Assert and Enforce

2012-03-14 Thread Dmitry Olshansky
On 14.03.2012 9:44, Chris Pons wrote: I'm new, and trying to incorporate assert and enforce into my program properly. My question revolves around, the fact that assert is only evaluated when using the debug switch. I read that assert throws a more serious exception than enforce does, is this cor

Re: Proper Use of Assert and Enforce

2012-03-14 Thread Jonathan M Davis
On Wednesday, March 14, 2012 06:44:19 Chris Pons wrote: > I'm new, and trying to incorporate assert and enforce into my > program properly. > > My question revolves around, the fact that assert is only > evaluated when using the debug switch. assert has nothing to do with the debug switch. All th