3 ms·
I have been building an internal tools development and deployment platform [1]. It is built in Go, using Starlark for configuration and API business logic. Sta
by ajayvk 2y ago
I have been building an internal tools development and deployment platform [1]. It is built in Go, using Starlark for configuration and API business logic.
Starlark has been great to build with. You get the readability of having a simple subset of python, without python's dependency management challenges. It is easily extensible with plugin APIs. Concurrent API performance is great without the python async challenges.
One challenge wrt using Starlark as an general purpose embedded scripting language is that it does not support usual error handling features. There are no exceptions and no multi value return for error values, all errors result in an abort. This works for a config language, where a fail-fast behavior is good. But for a general purpose script, you need more fine grained error handling. Since I am using Starlark for API logic only, I came up with a user definable error handling behavior. This uses thread locals to keep track of error state [2], which might not work for more general purpose scripting use cases.
[1] https://github.com/claceio/clace https://github.com/claceio/clace
[2] https://clace.io/docs/plugins/overview/#automatic-error-handling https://clace.io/docs/plugins/overview/#automatic-error-hand...
- jcmfernandes 2y agoThis is also one of my major complaints at this point. I'm building a developer tool with starklark resting at its core and I had already came across your work. I wish the starklark team had addressed it at this point.
- mahmoudimus 2y agoWe solved this by introducing a Result library. load("@.../result", result=result) def throw(arg): return 1/0 if result.Result(throw).map(arg).is_ok: # proceed else: fail("...")
- ajayvk 2y agoI wrote up the approach I used at https://clace.io/blog/errors/ https://clace.io/blog/errors/, started a discussion at https://news.ycombinator.com/item?id=42370488 https://news.ycombinator.com/item?id=42370488 since it could apply outside of Starlark also
- numbsafari 2y agoDoing much the same thing. Face similar issues. A lot of the complaints about Starlark as a programming language, and the proposed alternatives, seem to me to miss out on the UX advantages of having pythonic scripting (which so many folks who have taken a random "coding" class understand intuitively) whereas, e.g., using a lisp or lua would not. Further, having a language and runtime designed for safe use is absolutely critical, and trying to embed another runtime (js/wasm) and manage to lock it down successfully, is a much larger undertaking than I think folks realize.
- vlovich123 2y ago> Further, having a language and runtime designed for safe use is absolutely critical, and trying to embed another runtime (js/wasm) and manage to lock it down successfully, is a much larger undertaking than I think folks realize. For what it’s worth both Deno and workerd from Cloudflare give you starting points to run JS in a very locked down sandbox.