"Try it now"

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Apr 13 13:38:14 PDT 2011


I'm quite excited about the new look of std (right now realized only by 
http://d-programming-language.org/phobos-prerelease/std_algorithm.html). 
Here's a suggestion on how we could improve it more.

Adam wrote an in-browser evaluator for D programs. These, when presented 
on the homepage with "hello, world" in them are of limited usefulness. 
However, a personalized "try it now" button present for _each_ artifact 
in an std module would be of great usefulness.

When I try some html or javascript I find it very useful to go to one of 
those sites that allow me to try some code right then and there. The key 
aspect is that the code edit field is already filled with code that is 
close to what I'm looking for, which I can then edit and try until it 
does what I want.

Similarly, it would be great if next to e.g. 
http://d-programming-language.org/phobos-prerelease/std_algorithm.html#setUnion 
there would be a "Try it now" button. Clicking on that button would open 
an overlay with an edit window. The edit window initially contains the 
example text:

unittest
{
   int[] a = [ 1, 2, 4, 5, 7, 9 ];
   int[] b = [ 0, 1, 2, 4, 7, 8 ];
   int[] c = [ 10 ];
   assert(setUnion(a, b).length == a.length + b.length);
   assert(equal(setUnion(a, b), [0, 1, 1, 2, 2, 4, 4, 5, 7, 7, 8, 9][]));
   assert(equal(setUnion(a, c, b), [0, 1, 1, 2, 2, 4, 4, 5, 7, 7, 8, 9, 
10][]));
}

Then the user can change, compile, and run that program, to ultimately 
close the overlay and return to the documentation.

What do you think? This would require some work in the compiler (make 
unittests documentable, make their text available to ddoc macros) and 
some work in the front end. I hope this catches the fancy of e.g. 
Walter/Don and Adam.


Andrei


More information about the Digitalmars-d mailing list