Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand on the comparison page against Nix #103

Open
copumpkin opened this issue Feb 12, 2016 · 6 comments
Open

Expand on the comparison page against Nix #103

copumpkin opened this issue Feb 12, 2016 · 6 comments

Comments

@copumpkin
Copy link

It feels a little light on details. Given the extreme similarity between the language semantics, I'm curious what the motivation for creating jsonnet was in the first place. Was it a syntactic thing, aiming to be a superset of JSON, or were there other reasons? I see the OO stuff cited, but it's also not particularly hard to embed those semantics in a lazy language like Nix or jsonnet.

More than an answer on this ticket, I'd appreciate seeing the reasons expanded upon in the comparisons page (for posterity), although I certainly wouldn't object to both.

@sparkprime
Copy link
Member

Calling in @oconnorr for Nix fact checking purposes :)

Firstly I hesitate to add anything more to that page that isn't 1) completely objective 2) absolutely verifiably true. Most comparison of programming languages tends towards rationalizations of deep-seated ideologies and is not usually very productive. And of course the aim is not to bash Nix but to draw attention to the differences in a balanced way. But that said, maybe we could add more discussion on the page.

The languages are similar in that they're elegant, small, powerful, lazy, and have referential transparency. However the OOP semantics in Jsonnet completely changes the way programs are typically written. The laziness in Jsonnet is actually under-emphasized whereas in Nix it is essential for getting things done.

You're right you can build OOP on top of Nix as a library, and we even did that in the early days of Jsonnet as we were considering compiling Jsonnet to Nix. @oconnorr packaged that up and released it somewhere. But that's not a perfect user experience and is more interesting as an exercise than a soild foundation. Also, Jsonnet supports mixins and we never built that on Nix. I'm not certain it's feasible although I would not be surprised if it was. I've had a lot of experience with OOP frameworks on top of other languages (C, Lua, Javascript) but they never feel natural, they have a tendency to be very complex (in a manner that is not hidden when debugging / looking at stack traces, and you have to be disciplined to use them.

The other thing is being JSON-based. It's not just the syntax, there are big design compromises in Jsonnet in order to be an extension of JSON, e.g. supporting only doubles and not distinguishing between maps and objects. Another design goal was to be familiar to Javascript and Python programmers. We only deviated from this if we had a good reason. Nix has a functional "look and feel" and will appeal to functional programmers far more than Python programmers. On the other hand if you squint a bit, Jsonnet doesn't look so different from Python code (although obviously the semantics are very different). No matter how much you squint, Nix does not look like Python.

The heritage of Jsonnet goes back a long time within Google and unfortunately there is not a lot of public information I can share with you. You might be interested in http://alexandria.tue.nl/extra1/afstversl/wsk-i/bokharouss2008.pdf but I would not call that an authoritative document. OOP is an attractive paradigm for config because of the tendency to derive configs for different environments, locations, or purposes from "master" templates with the ability to override arbitrary details. And hermiticity is required for repeatability, which when combined with all the structured data manipulation going on, leads one towards a functional language that also has OOP as a core component. Nix is clearly underpinned by similar philosophies but the evolution is separate and the end result is quite different.

@roconnor
Copy link

I feel some of reasons for Jsonnet inlcude

  • Divorcing Nix the language from Nix the build system is slightly tricky.
  • Being a strict superset of JSON makes migrating existing JSON configurations easy and comfortable
  • Lots of programmers like OO semantics even though they are terrible. At least configuration management is one of the few situations where using OO programming is actually useful. Even Nixpkgs uses OO semantics, even if they fake them in a purely functional language.

@copumpkin
Copy link
Author

Those arguments all make a lot of sense. I appreciate you both writing them out for me, and think that a more profound acknowledgment of the similarities to Nix, and the deliberate decision to make jsonnet in spite of those, would add a lot of value to the comparisons page. When I first saw it, my reaction was "one of these is waaaaay more similar than the others, but the discussion of the differences feels superficial". I imagine others who already know Nix might have similar reactions.

@benley
Copy link
Contributor

benley commented Feb 14, 2016

Is there code shared anywhere for that earlier nix-based jsonnet implementation? I wouldn't expect it to be up to the current spec or anything, I just think it would be interesting to read over.

Also I'm particularly fascinated by that paper about GCLViewer; I had no idea that there was anything publicly released that discussed GCL! I have been contemplating trying to implement something similar for jsonnet, but at the moment I'm not entirely sure where to begin with such a project.

@sparkprime
Copy link
Member

No it never got past the stage of assessing feasibility. In fact the main thing that killed it was lack of floating point, which wouldn't really work with JSON. The OO library is out there somewhere, @roconnor can tell you where :)

@CMCDragonkai
Copy link

Just want to point out that Nix currently has floating point numbers but the docs say that Nix doesn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants