Live data from Hacker News

Duktape: an embeddable JavaScript engine

duktape.org

11–20 of 44 posts

Re: Duktape: an embeddable JavaScript engine

#11

If this is embedded in C++ I feel like you would be manipulating objects in the JavaScript scripts. JavaScript has OOP bolted on and it is not nearly as nice as Lua or similar alternatives. Why would a developer embed a JavaScript engine compared to something already existing?

The point is not, if a language is superior or has the better "OOP" quality. People tend to use what they know and JS is currently one of the "in" languages.

What is the benefit, if your scripting language is the price-winner from Harvard Business school or something else, but nobody knows it and wants to learn it. So many (good) languages have passed away, nearly unnoticed.

One of the big attractions of Java and JavaScript: The syntax. The C/C++ like syntax was and is just in fashion ... even when it is criticized by many. But everybody knows it and everybody (it seems) like it.

Re: Duktape: an embeddable JavaScript engine

#12

What is the advantage of something like this? (Not trying to be cynical, I just have no idea).

Developer Productivity

C/C++ is great for low-level and performance sensitive code, but at the cost of ease of use and a potentially slow compile-test-debug cycle. For instance, in a game engine, the Physics and graphics rendering are usually done in C++. But for the rest, you get more bang-for-your-buck with a higher-level language.

Mindshare

Other high-level languages can do the same thing. In fact, Lua and Guile were designed for this exact purpose. But Javascript works well and Javascript programmers are much easier to find. And if, say, you want your users to start writing plug-ins for your application, you'll have more success with a language they're more likely to know.

Performance

Thanks to the great Javascript JIT compilers, you'll probably take a smaller performance hit than with other high-level languages you might choose.

Re: Duktape: an embeddable JavaScript engine

#13

If this is embedded in C++ I feel like you would be manipulating objects in the JavaScript scripts. JavaScript has OOP bolted on and it is not nearly as nice as Lua or similar alternatives. Why would a developer embed a JavaScript engine compared to something already existing?

Qt already uses JS in the form of QtQuick with quite a bit of success. JS using a prototypal system means that it can emulate almost any other OOP trivially (while the reverse is much harder).

I prefer embedding lisp, but I realize that most developers don't know that language family (which mostly defeats the point of an embedded scripting language). JS seems to be the closest widely-known languages have come to this ideal, so I'm quite happy with the prospects of using it.

Re: Duktape: an embeddable JavaScript engine

#16

If this is embedded in C++ I feel like you would be manipulating objects in the JavaScript scripts. JavaScript has OOP bolted on and it is not nearly as nice as Lua or similar alternatives. Why would a developer embed a JavaScript engine compared to something already existing?

I wouldn't describe JavaScript's OOP as bolted on. It's just a different kind of OOP - prototype based rather than class based. You could argue that Lua is more "bolted on OOP" since there are quite a few different libraries that build OOP for it.

Re: Duktape: an embeddable JavaScript engine

#17
post #2

Very interesting. How large is the binary size?

The source is around 60kLOC and 2MB, so it's somewhere between the big ones like V8 and the smaller JS interpreters I know of:

http://code.google.com/p/tiny-js/ (~2kLOC)

http://code.google.com/p/quad-wheel/

Re: Duktape: an embeddable JavaScript engine

#19

Bloody wonderful! I'm quite pleased to see a compact and reasonable C interface for a JS engine--v8 can go eat a bag of rocks.

Agreed. I really like the engineering behind V8, but the interface is such a pain to work with. I actually switched my game from C++ to the JVM so I could use Rhino.

Re: Duktape: an embeddable JavaScript engine

#20
post #15

Great... If every aspect of lua wasn't better than js.

Lua is nice, no doubt about it, but it isn't better in every aspect.

Libraries count. Developer mindshare counts.

It's the same rationale as having so many modern languages that compile to Java. Java itself may not be that great, but man, there sure are a lot of useful libraries for it. Same with Javascript.

Post reply on HN