News for hackers. Stuff that matters.
Re:Bringing the Unix philosophy to the 21st century (2019) by eadmund on Sunday August 22, 2021 @01:27PM (#28267524)
Why not go all the way and use a format capable of expressing code and data? I refer, of course, to S-expressions.

They also have the benefit of properly handling numbers. Some might look at the absence of maps as a negative, but I think alists are preferable anyway due to their constant ordering.

Re:Bringing the Unix philosophy to the 21st century (2019) by lfnoise on Sunday August 22, 2021 @02:48PM (#28268284)
Yes. I never understood why JSON over s-exprs. The absence of maps is not a negative. S-exprs can represent maps. There are no maps in JSON, really anyway. It is just text. How that data is represented in memory is the output of parsing. You could just as well parse (dict (a 1)(b 2)(c 3)) into a hash table if you wanted. You could also have sets (set 1 2 3) or whatever other data structure.
Re:Bringing the Unix philosophy to the 21st century (2019) by iainmerrick on Sunday August 22, 2021 @06:08PM (#28270137)
You could do any of those things, but you have to pick a convention and other people have to agree on it.

JSON is nice in that it has just enough structure to do a good number of tasks in one obvious way. The biggest omission is probably some kind of time and/or date type (but ISO8601 in a string is the obvious solution there).

It’s not a coincidence that JSON was reverse-engineered from a language with convenient literals for dictionaries and arrays, and most languages provide those two collection types because they cover most use cases, so JSON fits most languages fairly well.

It’s just handy having both arrays and dictionaries available, rather than stretching one data structure to cover both, whatever Lua or Lisp might say.

Re:Bringing the Unix philosophy to the 21st century (2019) by lfnoise on Sunday August 22, 2021 @08:32PM (#28271107)
You parse the s-exprs and execute them in the context of a namespace of data constructors. Then you can have whatever data structures in memory that are defined by the constructors. This is NOT equivalent to having one data structure to cover both as Lua does. It is having one text format that can construct any kind of data structure in memory for which you have constructors defined.
Re:Bringing the Unix philosophy to the 21st century (2019) by iainmerrick on Monday August 23, 2021 @04:37AM (#28273526)
Okay, but we’re talking about a lingua franca for exchanging plain old data between different programs. You would have to pick your data constructors in advance.

I’m saying that arrays and maps give good bang for the buck, so you don’t really need to define anything beyond those. And if you accept that, having special syntax for arrays and maps is more convenient and readable than S-exprs.

Re:Bringing the Unix philosophy to the 21st century (2019) by eadmund on Monday August 23, 2021 @05:08PM (#28281977)
> And if you accept that, having special syntax for arrays and maps is more convenient and readable than S-exprs.

S-expressions are arrays, and maps are really just degenerate unsorted arrays of key-value pairs. Taking a look at https://json.org/example.html, I think this is easily more readable:

    (menu
      (id file)
      (value File)
      (popup
        (item (value New) (onclick "CreateNewDoc()"))
        (item (value Open) (onclick "OpenDoc"))
        (item (value Close) (onclick "CloseDoc()"))))
than:

    {"menu": {
      "id": "file",
      "value": "File",
      "popup": {
        "menuitem": [
          {"value": "New", "onclick": "CreateNewDoc()"},
          {"value": "Open", "onclick": "OpenDoc()"},
          {"value": "Close", "onclick": "CloseDoc()"}
        ]
      }
    }}
Re:Bringing the Unix philosophy to the 21st century (2019) by iainmerrick on Tuesday August 24, 2021 @07:02PM (#28296058)
Each to their own!

A big part of the difference is that all the JSON keys are quoted, which I agree is ugly (I like JSON5 myself).

You’ve also omitted the “menuitem” from the S-expr version. That could have been omitted from the JSON too but I assume it’s meant to be there for some good reason.

Re:Bringing the Unix philosophy to the 21st century (2019) by pjmlp on Sunday August 22, 2021 @03:42PM (#28268816)
Fear of parentheses, basically.
Re:Bringing the Unix philosophy to the 21st century (2019) by u801e on Sunday August 22, 2021 @04:36PM (#28269355)
But json already has quotes, commas, brackets and braces :-)
Re:Bringing the Unix philosophy to the 21st century (2019) by pjmlp on Sunday August 22, 2021 @04:46PM (#28269451)
Yeah, apparently finding misplaced quotes, commas, brackets and braces is magically easier than misplaced parentheses. :)
Re:Bringing the Unix philosophy to the 21st century (2019) by asoneth on Tuesday August 24, 2021 @10:49AM (#28289574)
You jest, but I find it easier to visually parse code organized using parentheses, quotes, commas, and brackets compared to code organized using parentheses, parentheses, parentheses, and parentheses. The latter approach is simple and elegant but makes it hard for me to read someone else's code.

I think the first reason is that the distinct characters provide a kind of visual checksum which makes me (slightly) more confident when initially matching a closing character to the correct starting character.

The second reason is that each character has a conventional meaning which makes it possible to form an initial guess as to its purpose.

Having said this, I freely admit this opinion may be colored by my only (paid) experience writing Lisp which was for a sprawling 20 year-old AI codebase mostly written by professors and graduate students who were often learning Lisp as they went.

Re:Bringing the Unix philosophy to the 21st century (2019) by kbrazil on Sunday August 22, 2021 @01:30PM (#28267550)
That’s a good debate to have. I settled on JSON due to its readability and ubiquity in web APIs. It’s something people all the way down and up the stack are very familiar with these days.
Re:Bringing the Unix philosophy to the 21st century (2019) by eadmund on Sunday August 22, 2021 @04:11PM (#28269132)
True, folks are very familiar with JSON, but it does have problems, and the best time to pick the best solution is before one has to deprecate a lesser solution. Computing is built atop a pile of decisions which made sense at the time and cannot be changed now due to compatibility (spaces in Makefiles, anyone?): there is no time like the present to simply choose to do the most correct thing.

'But folks won't use it!' Well, they might not. But if one gives folks a choice between the capability they need using an unfamiliar technology and not having the capability at all, they will learn the unfamiliar tech.

Re:Bringing the Unix philosophy to the 21st century (2019) by pjmlp on Sunday August 22, 2021 @03:41PM (#28268805)
Specially because it keeps being forgotten that Lisp Machines and Interlisp-D workstations shells were basically a graphical based REPL.

To put it in 2021 terms, Jupiter Netbooks in 1980's instead of PDP-11 green phosphor terminals.

Re:Bringing the Unix philosophy to the 21st century (2019) by johnlorentzson on Monday August 23, 2021 @04:22AM (#28273436)
Even the best Unix shells are a mere toys in comparison to what Lisp machines were doing in the 80s. I don't wanna say that using a Lisp machine was "life changing" or anything but let's just say I don't like Linux anymore.
Re:Bringing the Unix philosophy to the 21st century (2019) by pjmlp on Monday August 23, 2021 @05:19AM (#28273735)
I may look like very anti-UNIX, ironically I was big into UNIX, my first experience was with Xenix.

However my university library had a very good section on all kinds of OSes and programming languages since the dawn of computing, thus I could see how the future might have been and there was definitely a much better path, specially when coupled with my own experience across Amiga, Windows and Mac OS.

It is like the bulb paradox, just applied to OSes.

Re:Bringing the Unix philosophy to the 21st century (2019) by selfhoster11 on Sunday August 22, 2021 @02:04PM (#28267867)
I'd rather avoid mixing the two. Shell injection is already a danger.
Re:Bringing the Unix philosophy to the 21st century (2019) by quasarj on Sunday August 22, 2021 @03:40PM (#28268794)
Mostly because S-expressions are terribly hard for humans to read... and everyone is already familiar with javascript syntax.
Re:Bringing the Unix philosophy to the 21st century (2019) by geysersam on Monday August 23, 2021 @01:05AM (#28272490)
I feel that depends on the formatting. Non-pretty JSON isn't very readable either. ``` (dict :name apple :ip 192.168.1.1 :nested (dict :property value ) ) ``` Is almost JSON.
Re:Bringing the Unix philosophy to the 21st century (2019) by cylinder714 on Monday August 23, 2021 @02:40PM (#28280149)
Rivest's proposal includes an "advanced transport" representation, a more human-readable version. Here's a sample: http://people.csail.mit.edu/rivest/sexp-sample-a
Re:Bringing the Unix philosophy to the 21st century (2019) by johnlorentzson on Monday August 23, 2021 @06:58AM (#28274177)
S-expressions aren't inherently more difficult to read than JSON, it's just a matter of getting used to it.
Re:Bringing the Unix philosophy to the 21st century (2019) by HKH2 on Monday August 23, 2021 @10:53AM (#28276689)
Chinese isn't more difficult to read than English; it's just a matter of getting used to it.
Re:Bringing the Unix philosophy to the 21st century (2019) by cylinder714 on Monday August 23, 2021 @02:06PM (#28279726)
Obligatory links:

Rivest's proposal, with source code: http://people.csail.mit.edu/rivest/sexp.html

McCarthy's Common Business Communication Language: http://jmc.stanford.edu/articles/cbcl.html