emscripten

Vladimir Panteleev vladimir at thecybershadow.net
Tue Dec 14 10:17:05 PST 2010


On Tue, 14 Dec 2010 18:27:28 +0200, Alexander Pánek  
<a.panek at brainsware.org> wrote:

> D as server-side was once something I tried to achieve, but it wasn't  
> the right time. It would have been perfect as backend for a full-blown  
> JS browser app, only handling & shuffling data around, sending JSON back  
> and forth.

I've done this. I wrote three web-apps (HTML/CSS, JS+jQuery and D). It's  
awesome.

Two of the three are private, but here's the simplest one I wrote in 2006  
(no jQuery):
http://snoop.worms2d.info/ (basically web IRC client)

The biggest challenge with pure JS applications is getting back/forward  
buttons and bookmarking right. It's possible, and easy with the right  
jQuery plugins. However, preserving state which you can't squeeze in the  
URL is nontrivial (for example, the user submits a form, then clicks  
"Back" - normally the form would still be filled out on non-JS apps). The  
solution is storing the information in JS vars or the DOM (you could even  
leave the form HTML filled out).

D really hits the spot here, though. The apps' backends needed to be  
persistent and fast (things like searching through growable memory-mapped  
files), so CGI-like languages (PHP/Perl) were no good. With D's inline  
struct types and a JSON serializer, returning JSON is really clean and  
easy, which isn't possible in mainstream compiled languages:

if (resource == "/getfoo")
{
	struct FooResult { int n; string s; }
	return toJSON(FooResult(42, "bar")); // {"n":42,"s":"bar"}
}

-- 
Best regards,
  Vladimir                            mailto:vladimir at thecybershadow.net


More information about the Digitalmars-d mailing list