Sunday, September 23, 2012

Killa: my scripting language based in Lua and JavaScript

So I have been working these past months on my own programming language. It has been something that I've always wanted to do so I'm very happy that I can announce it here. Without further ado: Killa. I finished the 0.1 version months ago but real life just got busy on my end and I have been slacking this post for ages.

Killa (moon in the native tongue of my country) brings no new paradigm, neither disrupting ideas to the world of programming languages, to be honest I just stole some ideas from this book JavaScript: The Good Parts added some new ones from the top of my head and made it all work using the Lua 5.2 virtual machine, so... Why to bother? could you ask. Why indeed, with so many new and wonderful and exciting languages like Clojure, D, Haskell, Haxe, and trusted powerhorses like Python, Ruby and your favorite one here, creating a new half baked one could be just me following the new craze of "everybody can make his own programming language" (in 21 days).

Something of that was of course present, as I said before, I have always wanted to create a programming language, but even with that idea on mind, investing my time in a horrible language just for the sake of creating "my very own programming language" just doesn't click with me. If I'm going to create a programming language it better must be one that I'd really like to use, and I'm picky, programming after all has been my bread and butter for years. So I started saying that Killa just stole some parts of JavaScript and Lua, looking now backwards it's not surprise that I created Killa. I was not happy with any of them.

JavaScript. It had so many ugly parts that make me feel nervous every time I tried to do some fancy HTML5 stuff, at the end I did nothing (but that is not JavaScript fault, it was just me being lazy). Anyway, I could clearly notice that there were some beautiful gems hidden inside that jungle of errors and blunders. For starters, it was C-like, and C is one of my favorite languages. But, at difference of C, JavaScript had that "plastic" nature that made it powerful for solving problems in a dynamic way. First class functions, closures, that was cool.

Then it was Lua. I found Lua due to my work as a game programmer. Lua is kind of mainstream in the game industry for scripting, and it's a good little language, at least that was my first impression: it's pretty solid, it has a permissive license, an active community, it's very small and easy to embed inside your game engine, it doesn't take much memory and it's quite fast... but man: Why on earth have the array indexes to start from 1 instead of 0? and Why global by default variables? and Why the Pascal-like syntaxis? and Why not ternary operator? and Why not this and this and that? There were so many little annoyances that irked me daily. Somebody could think that I created Killa just because of external appearances, I don't think so. For me Lua was broken by the myriad of its little annoyances, but it's core was very useful and it was a waste not to use it.

I also believe that every programming language is by definition broken because none can do every task optimally. Lua was broken for me because I was a programmer working most of the time in a C-like world, having to change languages was a pain. By this definition, Killa is broken too, but it's broken for different people and for different reasons than Lua.

So I suppose that Killa has a place to fill and stay. I'm happy with the current status, but of course it needs lots of work to be stable. For now let me show you how the language looks, the little program below solves the Project Euler 393 problem under 9 seconds on my computer:

Not as fast as Python for this problem, but Python has the advantage of having immutable tuples that can be used as dictionary keys, I suspect that makes the above algorithm run faster in Python, because in Killa I had to use string keys and additional data handling was required. Also this problem needed support of big numbers that I added to Killa as an extension just now. It's just the port of lbc from Lua to Killa, but because the original library is under the GPL license I can not add it by default to Killa. I plan to maintain Killa under a permissive license for the sake of my fellow game developer peers. GPL-like licenses are very cumbersome for game development.

So, Who are the potential users of Killa? I think that anybody who likes the embeddable features that Lua has to offer but wants a JavaScript-like experience with many of its ugly parts removed. I could see Killa being used in the videogame industry or the embedded industry. To start things running (and for testing) I have already integrated Killa into two popular game engines: Love2D and cocos2d-x and I have made some small projects with them.

That's it. I need to explain with more detail the features of Killa in a future post, until then: happy coding!

UPDATE: I used bitwise operators to get the time down to 1.12 seconds, faster than Python (1.8 seconds)!

No comments:

Post a Comment