Live data from Hacker News

Q: A faster re-implementaiton of jq written in Reason Native/OCaml

github.com

91–100 of 196 posts

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#91
post #80
post #47

1) refuses to operate on stdin; requires a filename argument, which is so irritating. 2) doesn't accept values that jq accepts % time jq -r '[expression]'

Nothing that can be fixed later?

Thanks for this. I've been planning a similar work for years and haven't gotten off my ass (too many other projects lol).

I definitely agree that reading from stdin is critical if I'll be able to use it. Don't take the criticism too hard though (especially the "author doesn't appreciate unix" stuff. Sometimes we can be such assholes to each other).

Nice work!

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#92
post #47

1) refuses to operate on stdin; requires a filename argument, which is so irritating. 2) doesn't accept values that jq accepts % time jq -r '[expression]'

1 is easy to work around (handy tip incoming for any tools that _seem_ to not support stdin but actually do, as stdin is also available as a file in unix):

    echo '{"foo": "bar"}' | query-json ".foo" /dev/stdin

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#93
post #12
post #8

Are we sure it should get a single-letter 'q' binary name though? Docs seem to point that it's short for 'query-json'? Why not call it 'query-json' and let the user decide that as a shell alias or whatever. Even the ubiquitous 'ls' and 'cd' are two characters.

I made the same argument to him on reddit. q even exists already. He replied and thought about qj

Renamed :P

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#94
post #26

As an outsider I get very confused by the Reason / Reason Native / OCaml / Bucklescript / Rescript?! ecosystem. What does it mean for it to be written in Reason Native/OCaml?

That means it produces a native binary (for example, a .exe file on windows platforms), so ultimately you're aiming to run the program in a terminal. This is the normal way for OCaml to operate.

In this case the author is using Reason as an alternative syntax to OCaml. Reason resembles javascript a little more, and some people find that nicer to work with. So the idea is that you write Reason code, then translate it into OCaml code using the Reason tools, and then ultimately you compile it down to a native binary.

If instead you want to write a web-app which runs in a web browser or node.js, then you'd need to compile it to Javascript, which is what bucklescript helps you do.

Where does Rescript come in? As explained above, Reason can be used for writing either native apps or javascript apps. However, it's hard to evolve the syntax of Reason in a way which satisfies both aims. So they've now split the work -- going forward, Reason will specialize on native, and Rescript will specialize on javascript apps. Their syntax is expected to diverge from each other, in order to support those aims as best as they can.

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#95
post #13

I'd long for such a tool with a better comprehensible query language.

For anything moderately complex I iterate using https://jqplay.org/ . Life is much better since I started doing that.

Hint: you can do live jq query preview for any jq-like command using fzf. It looks like this for jql, an alternative I've created (you can find it in a neighboring comment):

echo '' | fzf --print-query --preview-window wrap --preview 'cat test.json | jql {q}'

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#96
post #54

Earlier quoted context omitted.

Yes, I don't understand how people end up with assertions that the filename is a require argument. At least we've got /dev/stdin or /proc/self/fd/0 as workarounds.

Much Unix software today is written by people who really don't appreciate or understand Unix. It leads to things like Homebrew (early on, at least) completely taking over and breaking /usr/local; to command-line utilities using a single dash (-) precending both short and long option names (granted, --long-opts is a GNUism, but it's a well-established standard); commands that output color by default even when the outp…

Anybody long enough to remember Unix from the beginning or even just the last 25 years... which is a tiny percentage of this site... should know that a unifying Unix or Unix "tradition" as noted in a follow-up comment is a pretty much a myth. The tradition is whatever system you grew up on and tribal biases you subscribe to and the only true Unix traditions are mostly trivialities like core shell syntax and a handful of commands, and a woefully underpowered API for modern purposes. And long option names are definitely not part of any tradition.

Myths like "everything is a file" or file descriptor is complete bollocks, mostly retconned recently with Linuxisms. Other than pipes, IPC on Unix systems did not involve files or file descriptors. The socket api dates to the early 80s and even it couldn't follow along with its weird ioctls. Why are things put in /usr/local anyway? Why is /usr even a thing? There's a history there, but these days I don't seem much of anything go into /usr/local on most Linux distributions.

It's also ironic to drag OS X into a discussion of Unix, because if there was one system to break with Unix tradition (for the best in some ways) -- no X11, launchd, a multifork FS, weird semantics to implement time machine, a completely non-POSIX low-level API, etc, that would be it.

All this shit has been reinvented multiple times, the user-mode API on Linux has had more churn than Windows -- which never subscribed to a tradition. There's no issue of lack of familiarity here, the original Unix system meant to run on a PDP-11 minicomputer only meets modern needs in an idealized fantasy-land. Meanwhile, worse is better has been chugging along for 50 years while people try to meet their needs.

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#97
post #81

Earlier quoted context omitted.

Much Unix software today is written by people who really don't appreciate or understand Unix. It leads to things like Homebrew (early on, at least) completely taking over and breaking /usr/local; to command-line utilities using a single dash (-) precending both short and long option names (granted, --long-opts is a GNUism, but it's a well-established standard); commands that output color by default even when the outp…

The `go` program uses -longopts and I think it would be hard to argue that Rob Pike lacks an appreciation of Unix traditions.

I would argue that Go's design as a whole is characterized by an attitude of ignoring established ideas for no other reason than that they think they know better.

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#98
post #94
post #26

As an outsider I get very confused by the Reason / Reason Native / OCaml / Bucklescript / Rescript?! ecosystem. What does it mean for it to be written in Reason Native/OCaml?

That means it produces a native binary (for example, a .exe file on windows platforms), so ultimately you're aiming to run the program in a terminal. This is the normal way for OCaml to operate. In this case the author is using Reason as an alternative syntax to OCaml. Reason resembles javascript a little more, and some people find that nicer to work with. So the idea is that you write Reason code, then translate it…

Thank you for the detailed answer! I check in on the status of the related projects from time to time and was often confused by the relationship between the components.

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#99
I used to be a regular user of jq, but I was never parsing very large JSON. I now do what I used to do with jq in my browser's developer tools console. Map and filter are far more familiar than jq's syntax where I found myself referring to the documentation most of the time.

I'm sure other people have use cases where the browser wouldn't meet their needs, but for me, I find jq unnecessary.

Re: Q: A faster re-implementaiton of jq written in Reason Native/OCaml

#100
post #22

This looks interesting, but could be confusing given the programming language of the same name ( https://code.kx.com/q/ )

Ah yes, the old ".j.k raze read0`" as a separate app

I should definitely check how that compares on some big files here.
Post reply on HN