by icefox · 11y ago · 0 comments
Wren is small. Wren is clean. Wren is fast. Wren is class-based. Wren is a scripting language.
If something is big, slow and message I don't care if it solves my problem when nothing else can. The only bullet point that comes close is the one talking about it being 'class-based', but I almost never hearing someone say "moving the code to classes will solve this problem". If that it is class based why would I use it over (as mentioned in the second sentence) Lua (or any one of the scripting "languages" that are just javascript in tiny form where I don't have to do any learning)? It seems like an easy pass for the majority of people that only read the main page.
What problems do users that need an embedded scripting language have? Just guessing, but probably #1 is the difficulty of integrating it into their existing project (and ease of extendibility with my app). Followed by language compatibility, control over garbage collection, and docs so I can spend more time on my app and less time mucking with the scripting language. I am guessing that something like these are the pain points that the main page should talk about.
http://munificent.github.io/wren/qa.html#why-did-you-create-...
> If something is big, slow and message I don't care if it solves my problem when nothing else can.
This is true of a general purpose language. I'm sure most Ruby or Python users couldn't tell you the first thing about how big or complex MRI or CPython is. As long as it works, it works.
Embedded languages are a different beast. When you drop something like Lua or Wren into your application, you're taking a direct dependency on its source code. You will end up stepping into in your debugger, reading its comments, etc. You will be shipping the language implementation itself physically with your application.
When that's the case, having a small, clean implementation becomes a very important feature.
> The only bullet point that comes close is the one talking about it being 'class-based', but I almost never hearing someone say "moving the code to classes will solve this problem".
Syntax is about usability, not utility. It's almost never a question of "Can I do this using classes." Everything is Turing complete, so you could use Brainfuck as your scripting language. The key question is, "Is it easier, more enjoyable, and less error-prone to use classes?"
If you're writing OOP-style code, which people increasingly do to script apps, I believe the answer is yes.
Here's an example of that kind of object-oriented programming in Lua:
Account = {}
Account.__index = Account
function Account.create(balance)
local acnt = {} -- our new object
setmetatable(acnt,Account) -- make Account handle lookup
acnt.balance = balance -- initialize our object
return acnt
end
function Account:withdraw(amount)
self.balance = self.balance - amount
end
-- create and use an Account
acc = Account.create(1000)
acc:withdraw(100)
Here's the same example in Wren: class Account {
new(balance) { _balance = balance }
withdraw(amount) { _balance = _balance - amount }
}
// create and use an Account
var acc = new Account(100)
acc.withdraw(100)
I believe this is a real productivity and maintainability improvement, and productivity is exactly what scripting languages are for.> Just guessing, but probably #1 is the difficulty of integrating it into their existing project (and ease of extendibility with my app).
Yup! That's also a key requirement (and one I still have a lot of work to do on.)
Edit: looks like your original comment made it through, and this repeat may best be deleted. Keep up the good work.
It's a totally fair point.
One thing I'm trying to keep in mind is who I'm marketing to. Right now, since Wren is so young, the people whose attention I want are not end users. They'd have to be half crazy to use Wren in its current state in a real application.
The people that will take an interest now are those that are keen on new languages for their own novelty's sake, or that are interesting in contributing to Wren itself. That's the audience I had in mind, and I think the bullet points make a bit more sense when you consider that.
Definitely, when Wren gets more mature, it makes sense to refocus the initial verbiage on what it can do for and end user.
In other words, will you have a more powerful C++ API on top of the plain old C API? Or is that a project for someone else, once Wren is a bit more mature?
Whether I implement or someone else and whether it ships with Wren are open questions, but I'm open to pretty much any answer for them.
I have played around with Lua for years, and I like it in theory, mainly because it has a nice implementation. The C API is especially nice (vs say Python).
But personally I think the language itself is ugly, and inferior to Python in almost every way. Python's classes are a bit annoying to me, but Lua's idioms for classes are even worse (and I never felt prototypes really lived up to their promise). I could never get myself to write anything more than toys with Lua; it was just cumbersome.
Wren looks like a really solid design. I think scripting languages went way too far to the "left" with prototypes and the dynamic behavior of classes (including JS, etc.). This seems a lot more sensible and usable. It looks a bit like Dart (AFAICT), which is probably no coincidence?
EDIT: I noticed that the embedding API is not fleshed out yet. Random drive-by ideas/questions:
- Are you going to model it after Lua as you did the parser? I don't think that's a bad place to start -- the stack-based model seems strictly superior to dozens of ad hoc methods like Python. And I believe Python itself is a lot cleaner than Perl, Ruby, v8, or the JVM. The Lua authors did a great job with this comparison paper: http://www.jucs.org/jucs_13_6/c_apis_in_extension
- I always wanted channels between C/C++ and a scripting language. That is, an idiomatic and supported way of running the scripting language would be in another thread. I think of it as a single-threaded "control plane" in a scripting language, and then multithreaded C/C++ for the "data plane". And you use Go-like channels to communicate between the two. I wrote something like this for Python and multithreaded C++ (which is a nice of making the GIL irrelevant). This can of course be implemented as an optional layer on top of a Lua- or Python-like API.
- I've only played around with this a little, but there is a newer CFFI package for Python: https://cffi.readthedocs.org/en/release-0.8/
It is a compromise between 1) the "old style" C APIs where you have to write tons of glue, and then it ends up being auto-generated with some tool that nobody understands like SWIG; and 2) the new style like ctypes or LuaJIT where you have to duplicate type information in your source code. If you mess up or the ABI changes then you get crashes.
CFFI has a model where you paste in incomplete C declarations and it safely generates a binding, which I think is quite nice.
I guess it is a little C-specific. Not sure how it would interact with C++. I think both C and C++ are important use cases.
Probably more convergent evolution than anything, but there are certainly similarities. :)
> Are you going to model it after Lua as you did the parser?
Yes, absolutely. My mantra is "when in doubt, do what Lua does", which works surprisingly well. I have so much respect for Ierusalimschy and company.
You can see the in-progress API here: https://github.com/munificent/wren/blob/master/include/wren....
> They did a great job with this comparison paper: http://www.jucs.org/jucs_13_6/c_apis_in_extension
Oh, man. This is perfect!
> I always wanted channels between C/C++ and a scripting language.
Wren is deeply built around fibers. It doesn't use the native C stack, so my hope is that it will be pretty easy to be able to suspend the interpreter to switch back to C and then resume it when you go back. All of the mechanism is there, I just have to see how it feels in practice.
You can build channels on top of fibers, so I'm really keen to play around with some different concurrency and communication models here and see what they feel like.
> I think both C and C++ are important use cases.
Me too.
Seems like there'd have to be a way to integrate with an event loop, and register a fiber with an event (edit or file descriptor/socket). Contemplating this makes me sleepy and grouchy ie it's very abstract, have you given any thought to this use case?
For me and my fellow disciples, it would therefore be really nice to have a constructor syntax that does this implicitly. So instead of writing:
class Customer {
new(customerNumber, name, address) {
_customerNumber = customerNumber
_name = name
_address = address
}
}
We could just write something like: class Customer {
new(customerNumber, name, address)
}
Or, if you like Scala: class Customer(customerNumber, name, address) {}
I'm a Java programmer by day, and some thoroughly depressing fraction of the lines of code in my codebases are of the form: private final AmazingObjectOfSomeKind amazing;
private final BrilliantObjectOfSomeOtherKind brilliant;
private final CrappyObjectOfAnyKind crappy;
public Foo(AmazingObjectOfSomeKind amazing,
BrilliantObjectOfSomeOtherKind brilliant,
CrappyObjectOfAnyKind crappy) {
this.amazing = amazing;
this.brilliant = brilliant;
this.crappy = crappy;
}
Users of other languages quite rightly point and laugh at me for this. Now, Wren doesn't have those types cluttering up the place, nor does it have the field declarations, but it does still have unnecessary verbosity, and that verbosity provides crevices for bugs to hide in (add a parameter to a constructor, forget to add a corresponding assignment). It might be nice to add a dash of syntactic sugar to eliminate this problem.Another facet of this school's approach is that objects are generally immutable. So instead of:
class Account {
withdraw(amount) { _balance = _balance - amount }
}
We would write: class Account {
withdraw(amount) { new Account(_balance - amount) }
}
(Although in fact, a bank account might be one of the cases where we wouldn't do this, but never mind)That gets old as soon as you have a few fields. Like:
class Account {
withdraw(amount) { new Account(_accountNumber, _sortCode, _balance - amount, _accountType) }
}
There's another bit of Scala sugar that is nice here - an automatic copy method which takes keyword arguments to override particular fields. Like: class Account {
withdraw(amount) { copy(balance = _balance - amount) } // other fields implicitly copied
}
Might something like that might be useful enough to justify its weight?Agreed. I'm on the Dart team at work, and in Dart you'd do:
class Customer {
int customerNumber;
String name;
String address;
Customer(this.customerNumber, this.name, this.address);
}
You do still have to declare them. I've thought about adding something similar to Wren. Since fields are already syntactically distinguished, it could be as simple as: class Customer {
new(_customerNumber, _name, _address) {}
}
I've hesitated because I want to see how much this is really needed in real-world code. I'm trying to keep things as simple as possible at least as first.> There's another bit of Scala sugar that is nice here - an automatic copy method which takes keyword arguments to override particular fields.
I'm not opposed to the idea, but it probably doesn't carry its weight. Wren is incredibly minimal. I like immutability a lot, but for scripting language where program size is relatively small anyway, I don't think it's quite as high a priority.