"Try it now"

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


On 4/13/11 3:54 PM, Adam D. Ruppe wrote:
> Andrei wrote:
>> 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.
>
> Indeed. I actually wrote a little javascript thing for that
> new home page that's reusable across other ddoc or similar
> sites. Check it out:
>
> http://arsdnet.net/d-web-site/std_algorithm2.html
>
> Every time it sees a d_code block, the script adds a button.
> Hit the button, and you can edit the code and send it off
> to my completelyexpendable vm to compile and run it.
>
> (It's also on my not-quite-done newsreader so example code in
> newsgroup posts are detected and made editable. That's less perfect
> since it's trying to pick code out of unstructured text, but it
> works reasonably well.)
>
>
> Of course, most examples fail to actually compile... but maybe
> a few replacement rules for the text - automatically insert main()
> if it's not there, import std.all or similar at the top,
> replace "..." with some generic data.
>
> I think we could make the examples work with just a few lines of
> code.

Whoa, what a coincidence we were thinking along the same lines (never 
saw that).

To take this to pro level:

* Button shold be on the same like as "Example:" and spell "Try now". 
Maybe a more attractive shape/icon could help too.

* Once pressed, the subsequent edit should contain a "Cancel" that 
undoes the action.

* The compilation/running results should come in a nice inline 
variable-height stdout after the edit window, not in a new undecorated 
page. I wouldn't mind some "terminal" color scheme for that stdout with 
e.g. green on black letters or whatnot. Anyhow, the entire 
edit/compile/run flow should be very very smooth.

* Syntax highlighting in the editor :o)

> Unittests are a different story though, since their code isn't
> in the HTML today. If dmd did make it available though, this same
> script should work on it.

Agreed. For now it would be terrific if you could take this proof of 
concept full course. I'll be waiting for your diff request!


Thanks,

Andrei


More information about the Digitalmars-d mailing list