After playing with duktape for a couple days I'm about as far up the learning 
curve as I was after a month of moz js.
In other words, moz is ungodly complicated, while duktape is clear and simple.
Neither is particularly readable or compact however, but at least duktape is 
straightforward, like cobol, where you write

add a to b giving c;

instead of

c = a + b;

So it's clunky, and takes an entire page of code to do something pretty 
obvious, but you can read it through without getting a headache, and you can 
write it without too much strain on the brain.
More important, you don't get a segmentation fault one time in 100, nearly 
impossible to debug, because you didn't root some value on your C stack and the 
mozilla garbage collector came along and removed it just before you used it, or 
you didn't autocompartment something properly, etc etc.
The moz api just cries out for catastrophic and irreproducible bugs.
I worked very hard to eliminate those kinds of bugs on the last rewrite, e.g. 
one entry point that sets the autocompartment, so at least you know you got 
that right, and rooting or handling everything else everywhere.
Well guess what, we don't have to worry about any of that shit in duktape!
If we get duktape working, and if jsrt passes, and it meets our needs, I don't 
think we'll ever go back to mozilla.
I can't imagine going back to mozilla.
I don't like to talk about burning bridges, but lordy the difference is like 
night and day, and I don't think we'd ever go back.
Which leads to my next question / observation.

You can define a class in C or in js.
I gave an example of the TextNode class in an earlier email.

TextNode = function() {
this.data = '';
if(arguments.length > 0) this.data += arguments[0];
}

This is a simple class with no setters, no side effects, and no particular 
reason to write it in C.
And of course it's 5 lines of js, and 40 lines of unportable C in either 
mozilla or duktape, since, as I say, both APIs make for long and wordy code.
So the advantage of js over c remains.
But here's the difference.

In mozilla or duktape, a class defined in C can be instantiated in c or in js - 
as you would expect.
In duktape, a class defined in js (as shown above) can be instantiated in c or 
in js, as you might expect, (I just tested this and it works), but this is not 
the case for mozilla.
A class defined in js cannot be directly instantiated from c.
You have to write something really ugly like

js_rooted_value val = js_execute("new TextNode('elephant')");
js_rooted_object my_text_object = js_value_to_object(val);
// Thus capturing the instantiated object.

Well that works fine, but your brain has to leave the c world, run some js 
code, and then jump back to c.
Also terribly inefficient if there are a lot of these, and if performance 
matters.
You can imagine calling up the js interpreter, running the js code, going back 
to c, over and over again, etc.
So there are a lot of classes that I left in c, because I needed to instantiate 
them in c, and I didn't want a bunch of circuitous code as shown above.
But then I have tons of unreadable, unportable, mozilla specific ugly c code to 
build some pretty simple classes and methods.
Now, on the brink of converting to duktape ... should I take advantage of the 
feature that duktape offers, a feature that every engine should offer in my 
opinion,
that I can instantiate any class, whether created in c or in js, using either c 
or js code, and it all works seamlessly?
I tell you, it would make things soooooooo much easier.
But it would make it a little bit harder to go back to mozilla 5 years from now 
if we felt we had to do that.
Not impossible, as illustrated by the js_execute("new TextNode") code shown 
above, but a bit more awkward to go back.

Personally I stand ready to march on and take advantage of this feature, thus 
simplifying the code considerably, because I don't think we're ever going back,
but if you-all can convince me that's a bad idea, then I guess I could leave a 
bunch of classes in C, where they are now, even though they're pure and simple 
and could easily be in js instead.
You'll have to do some fast talking though.
If I'm the one doing the conversion I'll want to clean things up along the way, 
and duktape makes that possible.
In other words, I've almost made my mind up already, but I'm trying not to be a 
dictator about things, so opening it up for discussion.

On a psychological note - depression saps all my energy, wherein the last thing 
I want to do is program, but if I start programming it helps with depression.
Kinda like exercise I guess.

Karl Dahlke
_______________________________________________
Edbrowse-dev mailing list
[email protected]
http://lists.the-brannons.com/mailman/listinfo/edbrowse-dev

Reply via email to