On 2011-05-18 21:09, Jesse Phillips wrote: > 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
Yes. Such assertions should always be passing. If he has a good reason for not just doing assert(arr.length != 2); then what the best choice is depends on what he's really doing. I haven't gotten the chance to read the article yet though, so I don't know exactly what he's trying to do. In the general case, however, I think that for documentation and articles, the best choice is to use assertions which pass - particularly those which use == - because then it's clear what's actually happening without having to run the code. - Jonathan M Davis
