News for hackers. Stuff that matters.
Re:JsonLogic – Build complex rules, serialize them as JSON by jcoffland on Tuesday October 25, 2016 @02:20AM (#12785719)
Adding computation to a data description language is always a bad idea. I've seen this done with XML. XSLT is a great example of why this sucks. This has been done with JSON before anyway. Here are several examples:

https://github.com/json-schema/json-schema/wiki/switch-(v5-p... http://www.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/jso... https://www.npmjs.com/package/lib-jsl http://jsonnet.org/language/design.html

Re:JsonLogic – Build complex rules, serialize them as JSON by keithb- on Tuesday October 25, 2016 @08:22AM (#12787254)
Okay, first of all, the current fascination with JSON is not fundamentally different from the previous fascination with XML. The only thing that anyone can agree on is that JSON is easy to parse just like its predecessor. This is why XSLT came into existence: firstly, it was easy to parse, secondly, ..., thirdly, profit (i.e. reuse, generalization, performance, etc. etc. etc.).

On the other hand, this language is bananas because the programmer is writing the AST and that is what a parser is supposed to do for him/her. Manually coding the AST is like harvesting an acre of corn by hand. If you can find a more inefficient method, then by all means use it.

And just for good measure, XML is not a "data description language", it is a type system; probably the most complex type system I've ever seen and it wasn't a bad idea, it was simply more complex than any application would ever need.

I don't dislike XML, and I think it will continue to live just like Haskell because every generation will come to understand that its extreme faith in generalization has little practical use just about the same time that a new generation first discovers it. So while one is dying to simplify, the other is dying to espouse the existential core of computer science.

Re:JsonLogic – Build complex rules, serialize them as JSON by falcolas on Tuesday October 25, 2016 @09:57AM (#12788000)
> XML is not a "data description language", it is a type system

XML means "eXtensible Markup Language" - so pretty much exactly a description of the data it contains. Granted, you can mark up a bit of data with a type, but you can mark it up with anything else as well.

I've even seen entire programming languages built upon XML.

Re:JsonLogic – Build complex rules, serialize them as JSON by drostie on Tuesday October 25, 2016 @10:10AM (#12788113)
I actually don't think that would be all bad if you in addition paired some parsers and serializers for other formats in your standard library.

That could actually be a really fun language: "you can write this in Haskell-syntax, Python-syntax, or C-syntax, we don't care, just make sure that you enclose it in the corresponding

    <parse-as lang="c">
    // ...
    </parse-as>
and then `myprogram.c.x` will get compiled to `myprogram.x` which is a standard XML file, which you can then edit with `x-to-py myprogram.x >myprogram.py.x && vim myprogram.py.x` and have a field day of it."

Sort of like the PL equivalent of Lennon's Imagine.

Re:JsonLogic – Build complex rules, serialize them as JSON by falcolas on Tuesday October 25, 2016 @03:21PM (#12790841)
It was moderately more complicated that this, as it represented the actual program tree structure within XML. Imagine lisp with XML tags in place of parentheses.
Re:JsonLogic – Build complex rules, serialize them as JSON by keithb- on Tuesday October 25, 2016 @01:05PM (#12789601)
> XML means "eXtensible Markup Language" - so pretty much exactly a description of the data it contains.

This is the belief that Eric Browne argued against in 2003[1]. "exactly a description of the data" only works when a human looks at it, which is the same argument for JSON. These two things "describe" the same object:

<person><firstname>Eric</firstname></person> { "person" : { "firstname":"Eric" } }

But using Browne's argument, a parser might see these objects as:

<hshhd><uueus>Eric</uueus></hshhd> { "hshhd" : { "uueus":"Eric" } }

How does that description help the parser?

What I'm saying is that XML is system for defining types, subtypes, relationships, etc. and that this type system can be used by programs that are written to interact with document instances in a way that is not dissimilar from other statically-typed languages. In a sense, you're agreeing when you say that XML has been used for programming languages because, in that case, a document instance might contain blocks of programming statements not instructions for a machine. It must be parsed and compiled first which takes some knowledge of the type system, i.e. how to create AST's and transform them into instructions.

I'm also saying that the problem with XML comes from the inability to reason about type systems in a general way. I can give you my XSD but will you know what to do with my data? And if I give you the XSD, and I tell you what to do with the data, then won't we writing the same program? Wouldn't it be easier to just share a library?

[1] http://workflow.healthbase.info/monographs/XML_myths_Browne....

Re:JsonLogic – Build complex rules, serialize them as JSON by falcolas on Tuesday October 25, 2016 @03:18PM (#12790814)
That's because there is no implicit data structure to XML mapping by default. This is a good thing; it makes XML much more flexible.

Of course, that flexibility is what burdened us with SOAP, XBRL, and other monstrosities; but I blame the creators of SOAP, not XML. XML is the "C" of the data markup world (simple but flexible), whereas JSON is more akin to "Java" (heavily restricted in capability, resulting in workarounds to represent complex concepts).

    { "hshhd" : { "uueus":"Eric" } }
How would JSON be any better in this case?
Re:JsonLogic – Build complex rules, serialize them as JSON by cabalamat on Tuesday October 25, 2016 @09:02AM (#12787561)
> Adding computation to a data description language is always a bad idea.

Unless it is Lisp s-expressions.

Re:JsonLogic – Build complex rules, serialize them as JSON by Corrado on Tuesday October 25, 2016 @09:36AM (#12787803)
I agree. This really makes me think of XSLT and all of the horrors that go along with it in real world usage. Maybe I'm not seeing the bigger picture but I don't really know how/where JsonLogic would be used and why it would be a better alternative than a programming language. Are there any examples that might clear it up for me? The linked site is documentation for the language but it's not helping me understand the need for this project.
Re:JsonLogic – Build complex rules, serialize them as JSON by dirtyaura on Tuesday October 25, 2016 @06:43AM (#12786748)
Why is it always a bad idea? For example there can be content that is triggered by rules and these rules need to be edited by non-programmers. Furthermore these rules need to be evaluate in different execution contexts (in our case in Android and iOS) This is a situation that requires describing simple logic alongside data.
Re:JsonLogic – Build complex rules, serialize them as JSON by vbezhenar on Tuesday October 25, 2016 @07:18AM (#12786909)
IMO it's always strictly better to use something real, like LUA. WoW uses lua as a programming language for user interface and users can make their additions (addons and macroses). A lot of users, who don't know anything about programming, can successfully use those lua snippets.

Also when real programmers have to interact with those systems (and my practice shows, that business users don't want to program, they ask programmers to do it), it's so much pain to use those GUI languages or whatever and it's so easy just to write some code in sane language.

Re:JsonLogic – Build complex rules, serialize them as JSON by josephearl on Tuesday October 25, 2016 @08:03AM (#12787150)
Apple has restrictions on downloading executable code, which downloading a Lua script would likely fall afoul of.

It's also a potential security risk - the downloaded script could perform things other than logic and so would require sandboxing/whitelisting of commands.

Putting logic in JSON avoids both of these issues since the actual handling of the logic is performed by a client-side library.

Re:JsonLogic – Build complex rules, serialize them as JSON by jfroma on Tuesday October 25, 2016 @08:26AM (#12787275)
Serious question, whats the difference between executable lua and executable json regarding apple restrictions?
Re:JsonLogic – Build complex rules, serialize them as JSON by michaelmior on Tuesday October 25, 2016 @09:56AM (#12787986)
JSON is not executable. Although I suppose you could argue that embedding an interpreter for a DSL like this inside your app is violating the restriction.
Re:JsonLogic – Build complex rules, serialize them as JSON by boomlinde on Tuesday October 25, 2016 @11:09AM (#12788608)
Lua isn't executable either. The point at which it results in some corresponding machine instructions wouldn't be much different in this case.
Re:JsonLogic – Build complex rules, serialize them as JSON by MichaelBurge on Tuesday October 25, 2016 @07:56PM (#12792831)
ELF binaries aren't executable either: They require the kernel to interpret them, preparing virtual memory and granting it a pid. Alone, they're just sequences of bytes.
Re:JsonLogic – Build complex rules, serialize them as JSON by boomlinde on Wednesday October 26, 2016 @02:13AM (#12794274)
What's your point? That you are willing to extend this principle to ELF binaries doesn't really affect my argument.

My point is that for the purpose of letting some non-trusted instructions run safely in a program, encoding them as JSON or Lua will come with the same caveats. Ultimately, they are both interpreted and can be sandboxed thus. Neither contain any code that will be passed off as-is for the CPU to execute. In some cases, neither does an ELF blob.

Re:JsonLogic – Build complex rules, serialize them as JSON by dirtyaura on Tuesday October 25, 2016 @09:53AM (#12787953)
To my understanding those restrictions have been lifted years ago. They used them strategically to kill Flash from becoming an app development platform and still probably can use them to kill cross-platform programming kits. But having scripting code in the app is not a problem anymore - they even offer Javascript execution context library in iOS SDK that makes it easy to run Javascript without UI. https://developer.apple.com/reference/javascriptcore/jsconte...
Re:JsonLogic – Build complex rules, serialize them as JSON by formula1 on Tuesday October 25, 2016 @11:01AM (#12788554)
While I agree this has been tried many times before, I still think there is room for another syntax.

- html/xml has become the definitive declarative ui language since it generally acts exactly how we expect it

- css queries and xpath have been effective at providing a way to search a structured tree

- regexp hqve provided us a way to search or structure strings

I dont find it absurd to believe that there can be a language for transformations