Scripting Languages

So I want to add a macro/scripting language to PN2. I have evaluated a number of alternative paths that I can take and now I want your feedback!

I looked at a number of scripting language and extension mechanism implementations available for C/C++. I then discarded most of them because of one of a number of reasons:

  • Couldn’t find easy information about how to embed the language
  • Language syntax too terrifying to force on PN users (e.g. Perl)
  • License problems
  • Too complicated to embed
  • Just plain didn’t like the language

Languages/Mechanisms I discounted: Perl, TCL, REXX, Ruby, MS Active Scripting, LUA

The two choices that I have in mind are:

Python is an option because it’s a language that I have grown to love and it comes with batteries included (meaning lots of useful libraries straight out-of-the-box). There are also a number of good ways to embed Python in C/C++ (although I have concerns). JavaScript I chose because it’s a well known language with large numbers of resources explaining how the language works. The SpiderMonkey implementation is very easy to embed and is fairly lightweight (400k).

Using Python as the default scripting language would require users to download Python to be able to run/create scripts. This is a 10+ megabyte download needed to benefit from scripting. This is quite a requirement. My concerns with embedding Python relate to the fact that you need to link to a certain version of the python library. Users would need to have the correct version of python installed to be able to use the integration. This could possibly be avoided through the creation of a dynamic-linking library for python embedding.

Using JavaScript as the default scripting language would allow distribution with PN adding perhaps 1 megabyte at most to the distribution. JavaScript doesn’t, however, come with much. Basic provisions are Array, Boolean, Date, Math, Number, RegEx and String. With these primitives, I can provide a good OO interface into PN allowing for lots of scripting goodness, but I can’t provide complicated things like the libraries of Python provide. This would really be a Macro system for PN rather than integration with a scripting environment.

Of course, the last alternative is to define a C/C++ extension mechanism to PN that allows the use of both (and potentially others). Provide a simple JS mechanism for macros and scripting out-of-the-box but also provide an optional Python extension that allows the use of Python for those that desire it.

So dear users, it is your time to influence my decision. Which of the above would you prefer, or do you (greedy user) want both?! Have I forgotton “your favourite scripting language ™” and you think I really ought to evaluate it before carrying on with my current crazyness? Get in touch!

Leave comments with your thoughts.

13 comments

  1. Well, I vote for JavaScript because of the requirements of Python and I already know JS good enough :)

    A way to support Python without enforcing users to download the 10MBs would be cool though…

  2. I would also like to see JavaScript scripting support.

  3. What I’d really like (somewhat predictably) is both – an extensible interface, bundle Javascript and let people download and add in python/ other stuff if they want.

    Great, but lots more work I guess :)

    However, if I could only have one, it’d be Python. This is Programmers Notepad, after all.- I’d imagine quite a few of your users would already have python installed (I do).

    Anyway, I’d just like to say thanks for PN, it’s a great peice of work; an extremely useful, well put together peice of software.

    Thanks for all your hard work.

    dunc.

  4. Perhaps Lua could be an option? SciTE includes it, so it should be easy to implement.

    To ability to use other scripting languages via a plugin would be useful (you could provide Python and JavaScript as seperate downloads).

  5. Scripting via .NET would be nice as well. It would allow for powerful extensions to PN2 (i.e. database access, preview in browser (via Cassini), any rich-client you can think of). Not sure if that is possible though (as PN2 is not written in C# or VB.NET).

  6. .NET plugins (and scripts I presume) are possible in an unmanged app, I’m just not sure about the amount of work tho :]

  7. I’m not clear what the goals are. What would the scripting be used to accomplish?

    If you’re looking for something extensible on Windows, ActiveX/COM is a requirement. There’s so much available via ActiveX, especially in regard to working with other applications. If the JS engine you’re looking at embedding has support for it, great; otherwise you’ll have to look for something that does support it.

    Along these lines, why specifically was MS Active Script discounted? One thing you gain with it is support for several different languages, plus implicit ActiveX abilities in all of them. (Though I’ll admit some AS implimentations suck — the PerlScript and Lua engines both have issues.)

    If the end goal is a way to get simple things done quickly, I agree that you want something lightweight, embedded, and well-known — such as JS. All the flexibility from multiple language support (or even one “big” one like Perl or Python) is simply not necessary. You’ll still want something that can call out to ActiveX/COM though. (Speaking of which, you may be able to use the AS interface to only the JScript engine. Then you’ll have a base to do other AS languages from later if desired, and won’t need to distribute anything extra with PN2 itself.)

  8. I’ve got to vote for Javascript. Everybody who uses your program will no doubt know Javascript already, so it will be the mose globally accepted choice.

  9. Okay, I started my programming career with Perl so I fail to see Perl as an ugly language. But the authour ruled that one out already so leave it that. However, even after numerous attempts I can’t make out Python. Guess it has something to do with the basic consept of having curly braces to separate blocks and semicolons to end the commands.

    So my vote goes against Python, anything else but it, please :-) .

    .Net sounded rather interesting, I’d be more than interested in that option if it is possible to implement.

  10. My opinion is exactly like Duncan Lock, prefer both python and Java script (or should be ECMA script ??), but if only one, Python.

    And anyway, I also to say thanks for PN, and I hope I can also use PN in OS/2 environment and Linux island. Our programmers use all these three platform here.

    Thank you and best regards,

    haydin.

  11. I’m also curious why MS Active Scripting was ruled out. PN2 is still my favorite editor, but when I have to work on SQL scripts, I end up going to PSPad for the Active Scripting support.

    Without hooks into ado through com (or, event better, ado.net), scripting would be of limited use for me.

    If the choices are Python or JavaScript, I vote JavaScript.

  12. Larry Hastings

    I’m for Python.

    The Python license doesn’t require you to schlep around all 10mb. I haven’t played with it yet, but I hear you can get the inner core of Python down to a slender 180k DLL. Add in just the libraries you think users would need for PN2 scripting and I bet you’d still easily be under 500k, and that’s before compression.

    If you did it that way, you could ship a lightweight Python environment with PN2, but automatically switch to the full-featured one if it’s installed. (Load it by hand with LoadLibrary() at runtime.) And if you did *that*, you should have some way for script authors to detect which environment they’re running in, presumably so they can complain if they’re not going to have some library or other.

    Cheers!