by antirez · 16y ago · 0 comments
At some point Redis will get scripting. It will take time, we are just entering 2.0 feature freeze, and later the priority will be redis-cluster, but we'll get scripting soon or later probably. Now I happen to be the original author of Jim, a small embeddable but fast enough (using an objects specialization technique) Tcl implementation. It's just a single .c file with 10k lines of C that is albe to run many Tcl programs unmodified if they don't tak with the "outside world" (that is no files, no sockets, no everything). It is really designed to be embedded, check it here:
http://repo.or.cz/w/jimtcl.git
Jim Tcl is actively developed, and used in OpenOCD (http://www.amontec.com/openocd/doc/About-JIM_002dTcl.html), in eCos environments and so forth.
But what I think is that users may get upset if I don't use a different language. The problem is, I don't know any single-c-file easy to embed, fast enough, interpreter for a language that will be more welcomed (I would like Javascript, for instance).
Also Tcl happens to be perfect to write Redis scripts, as they will look like commands issued with the redis-cli, like that:
register-command GETDEL key {
set result [GET $key]
DEL $key
bulk-reply $result
}
I wonder what will happen, if I'll go ahead or if there will be an alternative. I can't see how Lua is more elegant or better than Tcl, and while not hard to embed definitely not as simple and self-contained as Jim Tcl is. Also Lua is far from being a well known language.I really think that the right thing to do is to embed Jim Tcl, but there is a cultural barrier preventing me from doing this.
Btw, Lua is absolutely the best among all the JS / Ruby / Python / ... implementation I saw.
Without configure, and with a "Make ansi" target that is suitable to be used with the zero-configuration environment of Redis. So actually if it will not be Jim, it will probably be Lua.
* Most notably, the code to auto-reconnect while pipelining needs work, and I just finished moving, so it probably won't get touched for a week or two.
It has a translation of the entire official test suite into Lua (which was an ... interesting ... way to learn Tcl :) ), plus some other extensions for idiomatic handling of sets, lists, and zsets in Lua. (They're translated to tables with {key=true} for sets, {key=score} for zsets, and {key1, key2, key3, ...} for lists.) Also, the other Lua Redis library feels a bit more Ruby-ish to me.
I never got into Tcl, but that or Lua seem like the clear frontrunners as embedded config/scripting languages go. I'd prefer Lua, but it's your project, and I trust your taste.
However:
I really think that the right thing to do is to embed Jim Tcl, but there is a cultural barrier preventing me from doing this.
My datapoint as a happy redis user would be: Please don't. I have used TCL but don't like it. I also think there are rather few users who are versed in it and the obscure syntax would become a barrier to redis scripting gaining popularity.
My vote absolutely goes to Lua. That's still nowhere near as popular as javascript, python, ruby et al. But I think it's a much more accessible choice to people coming from the aforementioned languages (read: most people).
It's silly that there isn't a clean compact implementation of a strictly algol like language. Imagine C at higher level, or the basic PHP constructs without the stupid parts. This one:
function sum(a,b) {
return a+b;
}
No OOP, Data types: arrays, hashes, bool, integer, ... the obvious things, with operators to manipulate this stuff for the most boring tasks, and functions for all the rest.The lingua franca for scripting, as all the other languages will be bised in a way or the other.
Thing is, it wouldn't be that hard. How many compiler textbooks involve writing a minimal language like that? Tiger or Oberon, for instance. It's just that people don't stop at a tiny-but-sufficient, because they usually have a completely freestanding language in mind. Embedded languages need restraint to be useful. (Incidentally, I'm hoping to write a Prolog-ish language with embedding in mind this summer, but I already have a bunch of projects going.)
Lua is one of few cases where the authors have placed such a high priority on embedded use that the language has been kept small, even when it meant (gasp!) leaving things out of the standard library. It's more like a sane Javascript than an algol-like language, though. (I love it, but it's not everyone's style.)
function sum(a,b)
return a+b
end
Close, though. (The semicolon is optional, and typically only used with multiple statements on one line.)i think you being author of jim is biasing you hugely in this. lua is the obvious solution here, not tcl.
If nothing will change under the sun I think I'll use Lua even if I don't like the language too much, but sounds like the sanest thing to do.
That page describes the language in its entirety :)
The reality is that 95% of the programmers are not ready to such a choice :)
Heh, OK, Guile is not quite there yet. You can stop laughing now :)
What about defining a simple LL(1) grammar on top of tinyscheme and allowing both scheme and the Algol like language. Semantics would be scheme, syntax then is the choice of the programmer.
Scheme's primary advantages are that it has the most powerful compiler plugin framework which includes the most powerful macro system of any language, and it has the best language support for continuations. However, those two things alone have not been able to convince me to bite the bullet and force myself to code in Scheme for a year or more to really learn it, which is at least how long I think it would take to be comfortable in it.
I learned Just Enough TCL for some Expect scripts, and anyone who is working on problems that need the features Redis has aren't going to sweat a little TCL, IMHO.
Antirez, it would be interesting to read the thought processes you run through as you come to a conslusion.