[Article Contest, first draft] D Slices
Jesse Phillips
jessekphillips+D at gmail.com
Wed May 18 21:09:41 PDT 2011
Jonathan M Davis Wrote:
> 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
I agree, but he is conflicted on whether the assert should pass or fail. By your logic though it sound like you want it also passing. There isn't much difference between these:
assert(arr.length == 2); // error!
wirteln(arr.length); // 5
More information about the Digitalmars-d
mailing list