5 ms·
So why JSON of all things? When I reached the "write a full declarative program in JSON" section I was internally screaming "but s-expressions!"
by aaron-santos 10y ago
So why JSON of all things? When I reached the "write a full declarative program in JSON" section I was internally screaming "but s-expressions!"
- cocktailpeanuts 10y agocan you elaborate on s-expressions?
- emeraldd 10y agoAbout four paragraphs in https://en.wikipedia.org/wiki/Lisp_(programming_language) https://en.wikipedia.org/wiki/Lisp_(programming_language) "The interchangeability of code and data gives Lisp its instantly recognizable syntax. All program code is written as s-expressions, or parenthesized lists. A function call or syntactic form is written as a list with the function or operator's name first, and the arguments following; for instance, a function f that takes three arguments would be called as (f arg1 arg2 arg3)."
- cocktailpeanuts 10y agoOh yeah, I understand that part. I was just wondering what OP meant in his sentence.
- bpicolo 10y agoMeaning it's going far out of it's way to half-write a programming language in json rather than actually just using a lisp.
- cocktailpeanuts 10y agoBut why would you use lisp? I don't get it. No API returns data in a list format.
- bpicolo 10y agoLisps aren't limited to lists as data types, you can have anything you want. Lisp interpreters tend to be dead simple to implement.
- aaron-santos 10y agoEDN (s-expressions + Clojure's reader)[1] got a lot of attention when it was announced. It looks like it's garnered some use [2]. I was hoping to find a registered mime type "application/s-expr", but there are some uses out in the wild[3]. 1 - https://news.ycombinator.com/item?id=4487462 https://news.ycombinator.com/item?id=4487462 2 - https://github.com/search?utf8=%E2%9C%93&q=%22application%2Fedn%22&type=Code&ref=searchresults https://github.com/search?utf8=%E2%9C%93&q=%22application%2F... 3 - https://github.com/search?utf8=%E2%9C%93&q=%22application%2Fs-expr%22&type=Code&ref=searchresults https://github.com/search?utf8=%E2%9C%93&q=%22application%2F...
- aaron-santos 10y agoSure. S-expressions[1] are a notation for nested data structures. They can be used to spell out data as well as code. In fact both code and data look the same when expressed using s-expressions.[2] When the article's author describes both code and data using JSON, it sounds a little strange to me. While JSON is capable to describing nested data structures, JSON's syntax is much more verbose than s-expressions. I feel that since s-expressions have been around for about 60 years that the author should be familiar with them and address why a JSON encoding is superior to s-expressions for this use case. 1 - https://en.wikipedia.org/wiki/S-expression https://en.wikipedia.org/wiki/S-expression 2 - http://wiki.c2.com/?DataAndCodeAreTheSameThing http://wiki.c2.com/?DataAndCodeAreTheSameThing
- bijection 10y agoAlthough I'm also skeptical of coding in JSON, s-expressions are pretty close to a JSON subset (with the caveat that everything needs to be quoted). (x . (y . (z . NIL))) <=> ['x', ['y' , ['z', null]]]
- junke 10y agoThe first one is the flat list (x y z); the JSON one seems to be equivalent to (x (y (z nil))).
- bijection 10y agoYou're right! My scheme is rusty I guess. I should have said: (x . (y . (z . NIL))) <=> ['x', 'y', 'z']
- kazinator 10y agoIn Lisp, (x x x) denotes a list which contains three elements which are pointers to the same symbol object.
- hinkley 10y agoSame thinking, I expect, that gave us XSLT.
- allover 10y agoUsing JSON seems far more pragmatic than the mindset that gave birth to XSLT, so I don't really see the connection. JSON is widely used and understood, easy to parse and serialise to, and fundamentally simpler than most alternatives. You could argue that S-expressions are 'simpler' than JSON, but they didn't take off, for whatever reason - I'm not going to go into opinions on why I think that is, because that never tends to go well on HN :)
- stickfigure 10y agoXSLT was proposed as a limited transformation language, and actually (still) does a very good job of that. And since we're doomed to repeat the past we now see various XSLT-ish languages being developed for JSON/YAML/etc, relearning all the edge cases that drove XSLT into its current form. On the other hand, students of the past will notice that Jsonette looks awfully similar to Ant build files, which sucked. JSON/XML/YAML is a horrible way to construct general-purpose programs. Computing languages exist for a reason.
- hinkley 10y agoI spent a lot of time with Ant and was pretty good at it because I understood the tragically backward 'first writer wins' decision they made and had an elaborate set of techniques to work around it. That decision and the attempt to keep all conditional behavior entirely out of the build process wounded it gravely. The fact that they kept making compatibility breaking changes in minor version numbers was the genesis of my dim view of Jakarta projects. Once I started noticing the pattern I couldn't stop. I think we are finally starting to accept that Turing-complete data is a bug, despite what the Lisp people have been saying for 50 years, and is not a feature on the Internet. Microsoft served as the poster child in the 90's. The tension, I strongly believe, comes during debugging. When you are trying to figure out why the data doesn't look right, the less the code resembles the data being emitted, the harder it is to locate the source of the error. Templating engines get pretty close to addressing that concern, in ways that transforms or generators don't. So we keep trying to invent a better one. But once you let a little logic in, everybody wants all the logic. Ant found the Uncanny Valley, in a way that few other tools have managed. I think I'm okay with your implication that it was actually worse than XSLT, which is saying a lot. [edit] Ant is also the reason I shift uncomfortably whenever someone announces proudly that a tool was 'designed and implemented on a plane trip'. I'd rather have code you wrote when drunk than code you made while stuffed in a sardine can, subjected to noise levels that OSHA would have issues with, and suffering from altitude sickness. You literally designed this while your brain wasn't getting enough oxygen.