2016-02-07 8:07 GMT+03:00 tyru <[email protected]>: > On Sun, Feb 7, 2016 at 8:17 AM, Bram Moolenaar <[email protected]> wrote: >> >> 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(). >>> >>> Sounds great! >>> Do you have the plan to add jsencode() / jsdecode() ? >>> Or, will you merge the patch for those functions if I write? >> >> Feel free to make a patch. > > Okay, thanks! > >> >>> >> 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. >>> >>> Thanks! >>> Now I confirmed that 7.4.1269 raises an E474 error for the expression. >>> But yet it seems to return the string ('{"key":}'). >>> Is it intentional? >> >> When there is an error it returns what it has. Would it be better to >> return nothing? > > Hmm, patch 7.4.1270 seemed to fix this temporarily last night > and the result was totally what I was thinking; > which returns 'v:none' instead of what it has. > > An explicit error return value is better I think > because immediately we can notice something went wrong. > and if only a user checks the return value (without surrounding :try ~ > :catch), > a user can detect an error, like 'delete()' returns -1 with an error. > > let json = jsonencode({"key": v:none}) > if json is v:none > echoerr 'error!' > return ... > endif > > And sorry, tyru is a nickname. > The real name is Takuya Fujiwara. > I think you prefer a real name :) > (changed my nickname on google groups, too) > (oh, ':helpgrep Tyru' also shows my nickname in some places...)
Your code should not assume that execution continues after error. Wrap the whole thing into :try/:catch and `echoerr` will never be run. And it is not necessary you that will use :try/:catch, users of your plugin may do the same thing and it will stop. If you need to handle the error reliably use :try/:catch, there are no other options. And *never* use :echoerr, it has just the same problem: you do not know whether Vim will continue executing your code or :echoerr error will be transformed into exception, jumping to :catch, :finally or halting completely right after :echoerr. > >> >> >> -- >> You're as much use as a condom machine at the Vatican. >> -- Rimmer to Holly in Red Dwarf 'Queeg' >> >> /// 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.
