2016-02-06 20:42 GMT+03:00 Bram Moolenaar <[email protected]>: > > Tyru wrote: > >> Sorry Bram, I forgot to send this mail to vim_dev. >> Send again with +alpha about problems of current JSON features. >> >> On Sat, Feb 6, 2016 at 11:50 PM, Bram Moolenaar <[email protected]> wrote: >> > >> >> What do you think about this? >> > >> > I don't want to spend much time discussing this. v:null and v:none are >> > needed just like JavaScript has null and undefined. >> > >> > I was thinking of taking this a step further to a more efficient >> > encoding that is similar to Javascript. Unfortunately I haven't been >> > able to find a specification. I thought it was used in combination with >> > protocol buffers. Besides empty entries in an array, it also removes >> > the quotes around object item names. It's more efficient and doesn't >> > drop any functionality. We could add protocol buffer support, but let's >> > leave that for some other time. >> > >> > Also keep in mind that when you want to stick to the JSON standard >> > (well, one of them), you should not write the string yourself but use a >> > library to create it. Arguments that it's hard to type or spot a >> > mistake are hardly relevant. >> >> Okay. >> Now I know you seem to follow JavaScript syntax rather than JSON standard. > > True. Perhaps we should split this and add jsencode() / jsdecode(). > >> But please remind JSON is not only for JavaScript. >> It might be used for a communication with Vim and scripts, external >> commands, and so on. >> >> And more, currently, 'jsonencode({"key": v:none})' produces output >> '{"key":}'. >> This is not even a correct JavaScript syntax. > > I'll fix that. > >> And as ZyX said, please delegate the role of human readable format to >> other formats, like YAML. >> JSON should do just a communication work with something outside Vim. > > YAML has its advantages and disadvantages, I don't like it for > inter-process communication. > JSON is a nice format in many ways, although the requirement for quotes > isn't that nice.
YAML is for things like configuration files, it was never meant for IPC. JSON is one of the formats that tries to sit on two chairs: being format for IPC and being human-readable, mostly because of its background. And for IPC quotes do not matter and strict parser would be preferred because “incoming” messages are also generated by a computer and non-JSON stings indicate some bug. Though JSON does not fit for IPC used by Vim: buffer lines can contain strings which are not UTF-8, buffer names can contain such strings, variable values are also not restricted; and all this even if &encoding is UTF-8, so you can safely transfer basically no data*. Format which allows binary strings would be preferred here. * Python-3 bindings have exactly the same problem: you cannot use vim.current.buffer.name, vim.eval, vim.current.buffer[N] without possibly getting UnicodeEncodeError. Most plugins still ignore this problem which they can because it is not present in Python-2 and strings with characters that do not fit into &encoding are rare. May be fixed by using 'surrogateescape' when encoding, which is also one of the options for JSON, except that I cannot say how many implementations can accept string which contains only low part of the surrogate. Python JSON implementation accepts both strings `’"\"\uDCFF\""` (U+DCFF it is the result of using 'surrogateescape' to decode “UTF-8” string b'\xFF') and `"\"\\uDCFF\""`. > >> > you should not write the string yourself but use a >> > library to create it. >> >> Hmm, why? > > To avoid mistakes. But you can create the strings manually if you want > to, that's the advantage of using JSON over a binary format. Easier for > debugging too. And for writing tests. > > -- > hundred-and-one symptoms of being an internet addict: > 159. You get excited whenever discussing your hard drive. > > /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ > /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ > \\\ an exciting new programming language -- http://www.Zimbu.org /// > \\\ help me help AIDS victims -- http://ICCF-Holland.org /// > > -- > -- > You received this message from the "vim_dev" maillist. > Do not top-post! Type your reply below the text you are replying to. > For more information, visit http://www.vim.org/maillist.php > > --- > You received this message because you are subscribed to the Google Groups > "vim_dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
