> Steven Schveighoffer Wrote:
> > I always wonder about that. One of the issues with assert for people
> > "feeling" out the language is, a passing assert doesn't seem to do
> > anything.
> > 
> > For instance, in this example, if you take the code I wrote, and compile
> > it, you'll get a loud assertion error (proving the assertion runs and
> > fails).
> > 
> > If you take your code and run it, you get a command prompt. It doesn't
> > really help you see how it works.
> > 
> > I'm contemplating switching it to a writeln instead ;)
> > 
> > -Steve
> 
> Go with writeln, I understand that concern. The counter point I have is
> that this is how unittests work and much of the documentation has been
> written.

The huge advantage of assert over writeln is that it shows you what the result 
is supposed to be. If you're reading the code or documentation, that's 
extremely valuable, whereas writeln is useless. However, if what you're 
concerned about is running the code and see the result, writeln is far more 
useful. Since you're writing an article, I would definitely go with assert, 
but it really depends on what you're trying to do. assert works far better as 
documentation because you can see the result as you read, but writeln when 
running code because when you do, you can see the result.

- Jonathan M Davis

Reply via email to