From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Accept plists when serializing and parsing JSON Date: Sat, 2 Jun 2018 10:04:55 +0200 Message-ID: References: <87sh6awls5.fsf@gmail.com> <87in75bjvm.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000a26000056da4287f" X-Trace: blaine.gmane.org 1527926637 10027 195.159.176.226 (2 Jun 2018 08:03:57 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 2 Jun 2018 08:03:57 +0000 (UTC) Cc: Yuri Khan , Emacs developers To: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Jun 02 10:03:53 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fP1Vx-0002WZ-2l for ged-emacs-devel@m.gmane.org; Sat, 02 Jun 2018 10:03:53 +0200 Original-Received: from localhost ([::1]:58673 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fP1Y4-00022A-51 for ged-emacs-devel@m.gmane.org; Sat, 02 Jun 2018 04:06:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fP1XC-0001od-8m for emacs-devel@gnu.org; Sat, 02 Jun 2018 04:05:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fP1XA-0002tX-DT for emacs-devel@gnu.org; Sat, 02 Jun 2018 04:05:10 -0400 Original-Received: from mail-oi0-x242.google.com ([2607:f8b0:4003:c06::242]:45697) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fP1XA-0002s3-4a for emacs-devel@gnu.org; Sat, 02 Jun 2018 04:05:08 -0400 Original-Received: by mail-oi0-x242.google.com with SMTP id b130-v6so24379640oif.12 for ; Sat, 02 Jun 2018 01:05:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/pYZPz9xL0+aM4aBG3nqNEfu9iw8AyYEKSSMuYQBvRQ=; b=DgzF0cuV868hmjlva2i3dY7wmhhs8t2tcENtG7/VLn3/7Xe7+s/2RC7aw9ycZNtIBX 0BjoufHTYP38EKnlqteSOvS6zRymkhZPws3/Cc/pW0bjdKkxlPqMxDBj/KEsK4uAaK/A SGI1HjF1dqbg/8OsWpTDv/bXz7+t8NbmxmEO399Y5/ipKgHK6b0MIiPaPkJh1Yf2vG8o XbUqltHmbHXedAgMTZ6gEJuGaoz4sB9ts09ljzW3hAQzlcns0RLnlIcwabDZJQyHIrVF zcURIKztOLukdj+/9zxZplAUuvEpwkS1npOTKhP1GUBWX+m1M0VNIS4hLq/zjYLywUjx JNtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/pYZPz9xL0+aM4aBG3nqNEfu9iw8AyYEKSSMuYQBvRQ=; b=rfJY/3fkgJF/FSzQ7m7jLOfq4R9mOW3/aDATUc9UD8JyYEB8VWHCDivAH2aKUsQkqF JXwQqm5YZNLUVc8TGHnvOIulD7RJRIK7xBrB7Iehsk5Oq7YefV8cKHodbgSzJuNZb7BA Yut8wu/YYrlBQm+cTBDY3z6BNwtigvEJMw2V5niRhintmeF3+07pb+vUZCtl6Q21eWb8 I+3OP1dsOdlh/qblxOFLKFeRliTA3R8N83daCCTFbjjoh1kbQtFyiJex55JVGPnPf5rX qx9Y3SfHWBI6TVwFoUYbK6rcz24qGaAlGqZHAghBJxkpbzzm/MWUZstiYfh8p9gJIXUN XhSw== X-Gm-Message-State: ALKqPweb2v9p0mWu+ud5kyqpaY2oI0W1GIOQTYCPap48YwklhJb6k93c AtwX4kUjFuDlk5Jkq7UMtvF9uS6hI6CzE3uet4g= X-Google-Smtp-Source: ADUXVKLx3ZQrMroa7eo6QxON6xNagHKO2CP0yPAT2VSCbM1Q/+12MFs3Y7nqa6kpIKZnK6MV/C/eONIjB6iC83mFeRA= X-Received: by 2002:aca:3f04:: with SMTP id m4-v6mr8086628oia.198.1527926707337; Sat, 02 Jun 2018 01:05:07 -0700 (PDT) In-Reply-To: <87in75bjvm.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::242 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:225914 Archived-At: --000000000000a26000056da4287f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Jo=C3=A3o T=C3=A1vora schrieb am Mi., 30. Mai 2018 u= m 10:58 Uhr: > Yuri Khan writes: > > > On Wed, May 30, 2018 at 5:31 AM Jo=C3=A3o T=C3=A1vora > wrote: > > > >> Well, it's not really "global state" in the sense I believe you're > >> talking about, because no part of the library is maintaining any state > in > >> global variables -- it's read-only from json.c. > > > after ironing out all [the other?] bugs related to shared state > > Which ones? Those seem to be precisely the ones I meant to say are > excluded because the var is read-only. > It is not read-only. If it were read-only, it would be just a constant and not a variable (in the imperative programming sense) at all. > > > * =E2=80=98foo=E2=80=99 wants plists while =E2=80=98bar=E2=80=99 wants = alists. > > If "want" is the same thing as "must have", then bar should be setting > the var from the beginning, end of story. It should only not set the var > if it doesn't care. > (Almost) every caller cares about the return type of the function call; what else should it care about? That means that every caller would have to set this variable, turning it into a parameter, just with awkward syntax and subtle, easy-to-get-wrong interface. > > There are many variables like this in emacs. Yes, unfortunately. That's no reason to introduce new ones. Emacs was written in simpler times (the 1970s?) when the amount of code in the world was much smaller and people didn't yet know everything that we now know about software engineering. That's OK; if you look at Fortran code from that era it also looks very different from what people would write today (six-letter function names, a single static callback function, customization happens generally by copying and modifying functions, ...). But we have 2018, so we should apply the accumulated wisdom from the last decades. > Eli recently reminded me in > a closely related thread I have to bind coding-system-for-write around > process-send-string, for example. > Yes, that's necessary because the existing interface of process-send-string uses dynamic variables as hidden parameters. That's unfortunate, but no reason why other, unrelated APIs should also do that. > > Obviously, the pitfall is overlooking to bind them when you have > to. Presumably this is outweighed by the convenience of not passing a > trillion args to a function call and, more importantly, to every caller > of a function, like in the commit that removes the var, which is quite a > bit more complex (which is why I started with the other alternative). > No, it's never outweighted. If there are too many parameters, you'd collecting them in an "options" object and pass that around, or create a "JsonDecoder" object that keeps the settings, etc. > > Anyway, this point could be irrelevant if we remove the variable and > argument completely, auto-detecting plists. Can't decide if that could > be a worse idea, though. > > It might be because it could make the interface more surprising. There's a clear type difference between hashtables and lists, so detecting them automatically is fine. But "plist" isn't really a type; there's no fundamental difference between plists and alists, and the only difference is how they are used (assq vs. plist-get etc.). That's one of the (several) reasons why I decided to not support plists in json.c at all, and I'm still not convinced it's worth the additional interface complexity (for deserializing the story is probably different, as it doesn't make the existing interface more complex, and with the CL argument lists you already have an actual use case). --000000000000a26000056da4287f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Jo=C3= =A3o T=C3=A1vora <joaotavora@gma= il.com> schrieb am Mi., 30. Mai 2018 um 10:58=C2=A0Uhr:
Yuri Khan <yurivkhan@gmail.com> writes:

> On Wed, May 30, 2018 at 5:31 AM Jo=C3=A3o T=C3=A1vora <joaotavora@gmail.com> = wrote:
>
>> Well, it's not really "global state" in the sense I = believe you're
>> talking about, because no part of the library is maintaining any s= tate in
>> global variables -- it's read-only from json.c.

> after ironing out all [the other?] bugs related to shared state

Which ones? Those seem to be precisely the ones I meant to say are
excluded because the var is read-only.

= It is not read-only. If it were read-only, it would be just a constant and = not a variable (in the imperative programming sense) at all.
=C2= =A0

> * =E2=80=98foo=E2=80=99 wants plists while =E2=80=98bar=E2=80=99 wants= alists.

If "want" is the same thing as "must have", then bar sh= ould be setting
the var from the beginning, end of story. It should only not set the var if it doesn't care.

(Almost) every = caller cares about the return type of the function call; what else should i= t care about? That means that every caller would have to set this variable,= turning it into a parameter, just with awkward syntax and subtle, easy-to-= get-wrong interface.
=C2=A0

There are many variables like this in emacs.

Yes, unfortunately. That's no reason to introduce new ones.
Emacs was written in simpler times (the 1970s?) when the amount of code in= the world was much smaller and people didn't yet know everything that = we now know about software engineering. That's OK; if you look at Fortr= an code from that era it also looks very different from what people would w= rite today (six-letter function names, a single static callback function, c= ustomization happens generally by copying and modifying functions, ...). Bu= t we have 2018, so we should apply the accumulated wisdom from the last dec= ades.
=C2=A0
Eli recently re= minded me in
a closely related thread I have to bind coding-system-for-write around
process-send-string, for example.

Yes, = that's necessary because the existing interface of process-send-string = uses dynamic variables as hidden parameters. That's unfortunate, but no= reason why other, unrelated APIs should also do that.
=C2=A0

Obviously, the pitfall is overlooking to bind them when you have
to. Presumably this is outweighed by the convenience of not passing a
trillion args to a function call and, more importantly, to every caller
of a function, like in the commit that removes the var, which is quite a bit more complex (which is why I started with the other alternative).

No, it's never outweighted. If there are= too many parameters, you'd collecting them in an "options" o= bject and pass that around, or create a "JsonDecoder" object that= keeps the settings, etc.
=C2=A0

Anyway, this point could be irrelevant if we remove the variable and
argument completely, auto-detecting plists.
Can't decide if that could
be a worse idea, though.


It might b= e because it could make the interface more surprising. There's a clear = type difference between hashtables and lists, so detecting them automatical= ly is fine. But "plist" isn't really a type; there's no f= undamental difference between plists and alists, and the only difference is= how they are used (assq vs. plist-get etc.). That's one of the (severa= l) reasons why I decided to not support plists in json.c at all, and I'= m still not convinced it's worth the additional interface complexity (f= or deserializing the story is probably different, as it doesn't make th= e existing interface more complex, and with the CL argument lists you alrea= dy have an actual use case).=C2=A0
--000000000000a26000056da4287f--