"Try it now"

Jonathan M Davis jmdavisProg at gmx.com
Wed Apr 13 17:58:31 PDT 2011


> On 4/13/11 6:11 PM, bearophile wrote:
> > Adam D. Ruppe:
> >> * Since most of them don't actually output anything, the program
> >> 
> >> now detects output.length == 0 and says "Program run
> >> successfully." upon completion to give some feedback.
> > 
> > This is a problem. Unittest code is not meant to produce an output, while
> > online snippets to try are meant to nearly always produce a meaningful
> > output.
> 
> I disagree. I find examples that use assert() much clearer than examples
> that print something to the console and then explain in a comment what
> you ought to be seeing.

I concur. The use of asserts in the examples is generally very clear. It also 
works great as a unit test, so if/when we make it so that ddoc examples are 
taken from unit test blocks, it works out really well. The example is both 
documented and tested. You can't do that with a print statement and a comment.

- Jonathan M Davis


More information about the Digitalmars-d mailing list