5 ms·
For the JSON case, it doesn't make sense to use an empty object as a sentinel, for sure. JSON parsers usually have their own sentinel for `null`. Lua has a lot
by nikki93 6y ago
For the JSON case, it doesn't make sense to use an empty object as a sentinel, for sure. JSON parsers usually have their own sentinel for `null`. Lua has a lot of issues, but `nil` being not-present hasn't been an issue that has come up a lot in practice. If you have any specific cases where that has been an issue, would be interesting to hear about them.
- aasasd 6y agoAs I wrote in the first comment, the use-case is e.g. API integration, which is what ‘scripting’ often is, these days. More widely, any transformations or filtering or helper code where you accept structures and pass them on after mild fiddling—again, quite typical use for Python or JS if you ever pipe data between scripts in the terminal or over the network. You don't put your data schema in each of those scripts and maintain them on every change at the source. Imagine implementing `jq` in Lua with all those ‘sentinels’ throughout the whole function library. The issue is that interoperability is crippled. The fact that you haven't so far run into these use-cases doesn't help with the problem that an entire, very common, class of functionality can't be done without tracking those nulls at each and every step with some crutches that bring their own troubles.
- nikki93 6y agoYeah I actually don't think Lua is great for those things, tbh. Lua is not a good tool for manipulating JSON--JavaScript is probably sensible for that (it is JavaScript's object format, after all). And yeah I don't think it's good to use a bunch of external libraries in Lua, since as you say there's not a common ground for how data is organized. The libraries I rely on are are more native integration things like lpeg, luasocket, luasec, love2d, ... They've all been quite good. And yeah you keep saying 'sentinels' in quotes but honestly it's worked fine when using lua-cjson. There's always an impedance mismatch between JavaScript's object format and Lua's though. Lua also allows non-string keys which are great in Lua but not a thing in JavaScript, and in practice I've found the array/object-table mismatch more problematic than `nil`/`null` and so on. I've mostly applied Lua for embedding in game engines, and to that end there's nothing that comes close, short of rolling your own VM that's exactly built the way you want. The main way to use it I think is to embed it somewhere and build up the set of utilities / libraries that you need to script over. But yeah it's not great for API glue code bc. APIs tend to bias toward JavaScript / JSON and other ways of doing things.
- aasasd 6y agoWell, my lament in the first place is that Lua could be a good and fast general-purpose scripting language. Instead, I can have ‘good’ but then I'll have to sit around twiddling thumbs while Python or JS start up. Especially Fennel runs circles around ClojureScript in terms of toolchain and build-cycle lightness. JSON is pretty non-specific to JavaScript, which is probably a part of its popularity. And it's not the only serialization format. Null works about the same way in the majority of popular languages—so you're bound to need it for interoperability if you go outside C. By libraries, I mean Lua libs like Penlight. Once you touch functional programming and function composition, you want structures to be preserved as they are, unless explicitly mangled. > And yeah you keep saying 'sentinels' in quotes It's because I haven't seen that notion before, at least under this name.
- nikki93 6y agoHave you tried lua-cjson, out of curiosity? They use a cjson.null (or something like that) value for nulls in JSON. But yeah agree with what you've said in general, if I had to do some API JSON manipulation Lua isn't what I'd jump to, even though I'm pretty familiar with it. Do Python or JS actually take that much longer to start up for a script? Node starts up pretty quickly on my system.
- aasasd 6y agoNow that I think of it, cjson.null might be workable even with data-transformation libraries, since it's some Lua meta-voodoo-value that can't come in the input from other systems. But then, of course, there's the problem that other data-exchange libs invent their own voodoo-values for null, like ngx.null. Precisely because they need it for actual integration use-cases. As for the performance, I happen to use an underpowered machine, which is how I discovered the drastic difference with Lua. However, performance still matters beyond just ‘pretty quickly’ if you consider desktop software, especially productivity software—which has to be snappy. Scripting your productivity software is a textbook case for dynamic languages, and almost the exact niche for Lua. Even on my machine, there was a moment when I had to make sure that Alfred actually called my Lua script—because the results popped up immediately (despite going through the command-line interpreter, not Luajit). Meanwhile, people are making productivity software with Electron or Python, which to me verges on ridiculous.
- anonymoushn 6y agoImplementing jq doesn't sound too bad I guess.
- anonymoushn 6y agoAn acquaintance needed to send msgpack messages containing nulls to redis and found that 0 of the existing msgpack libraries were capable of that.