Skip to content

30 minutes...

Friday, 7 May 2004  |  geiseri

As an exersize I have been exploring the feasibility of migrating from KJSEmbed scripts to C++...

Anyone who has worked in industry for any length of time is completely aware of how those temporary solutions become not so temporary. Usually these over time get less and less maintainable, and more of a liability. I have seen this a few times with one off perl scripts that keep a system up and running, or a simple VB app that is used to order supplies from the mail room. In both of these instances they where a one-off temporary solution that lived on for years and years... the VB app was VB3 on windows 3.11 and the Win95 migration played hell on it... the original author was gone, and no-one knew how to get it to work with our other applications (written in Delphi, not much better).

So we started over from scratch... I hate not being able to preserve work done...

KJSEmbed has a unique opportunity. Javascript has a C++ish nature in its constructs, with a few differences. With the Qt bindings I have been finding that Javascripts can be converted in little time with little effort. IMHO this makes KJSEmbed less of a liability as a solution for problems. The problem can be solved with KJSEmbed now, and when the first sign of trouble appears it can be migrated to C++ very easily.

This was the case with a small application I wrote in KJSEmbed last fall. It was the subject of my first KJSEmbed article. We needed something that could integrate better with our other apps, and we where not in the mood to rewrite the bugger from scratch. It was tested, and working, it was just not viable to stay in its current state.

So I took out to convert it over to C++. Shockingly it took me about 30 minutes, including a few surprises with C arrays vs Javascript arrays. Can you tell the difference? [image:460]

250 Lines of javascript converted to about 300 Lines of C++, including the code to make it a kpart that loads into our app. As I collate these details, I think there is a powerful message here for KJSEmbed as both a prototyping language, and a safe platform to base new applications off of.