-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
builtin.jq: whilst #2776
base: master
Are you sure you want to change the base?
builtin.jq: whilst #2776
Conversation
whilst is like while but more conventional. builtin.jq: lpad, nwise, whilst Retain _nwise for backward compatibility. lpad: left pad whilst is like while but is more traditional. jq.test
def _while: | ||
if cond then ., (update | _while) else empty end; | ||
_while; | ||
def _while: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to define a code style for jq. I've become very happy with 4-space indentation except for 2 spaces for |
, like this:
.
| stuff
I think until we decide on a style for jq code, maybe it'd be best to not restyle existing jq code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just trying to ensure while/whilst/until were consistently formatted, admittedly in the 2-space style -- two spaces saves space-time, no? I thought that was important for builtin.jq ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing style of surrounding code to be more consistent is something I like to do -though it can be irritating because it clutters diffs and complicates use of git blame
-, but in this case I'm not sure what style we ought to adopt, and my own jq-coding style has change over time, so for src/builtin.jq
I would prefer we don't gratuitously re-style until we decide on a style. Conversely, I'm not asking you to adopt a style for jq code for now either -- if eventually we have to restyle all of src/builtin.jq
, so be it.
(For C code in jq the style is fairly consistent already, and very much in @stedolan's C style.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicowilliams - In case you haven't noticed, @itchyny's builtin.jq in gojq uses the two-space style :-)
https://github.com/itchyny/gojq/blob/main/builtin.jq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pkoppstein no, I've not noticed. It's on my list to eventually go take a look at fq
, jqjq
, gojq
, rq
, and others, but my time is limited. What they do for style is interesting, but what they do for semantics is much more interesting as we want jq-alikes to interoperate. As for style, like I said, my own jq style has evolved and I think we should discuss that separately and not gratuitously restyle src/builtin.jq
for the time being even though I otherwise would prefer that we do restyle as we go.
Any reference to convince this naming is adopted somewhere else? |
More conventional? I think I made a mistake making |
@itchyny wrote:
Who knows? I couldn't think of a better name, and the functionality of the proposed
In other words, this distinction which can be drawn in English parallels the distinction between the proposed and existing jq defs. (I was toying with |
@nicowilliams wrote:
Believe me, whilst/2 was born of necessity. On the web:
By saying "whilst is like while but more conventional", I meant that this new def is somewhat similar to jq's existing https://www.tutorialspoint.com/cprogramming/c_while_loop.htm Perhaps those familiar with such "while" loops would prefer that the "while" in builtin.jq behaved like that, but that's water under the bridge. |
For larger jq source files i've settle on a haskell/elm-ish style, 2 space indent and then explicit parentheses if some pipelines ends up multiline to make them align nicely and looks similar to array and objects literals. Also for some reason started using underscore to prefix for local functions. Can have a look at jqjq if you want an example. Also wish there was a jqfmt (and vet/lint) :) |
Honestly feels kind of a literature that non-native speakers cannot tell the difference (or even worse cannot spell correctly). |
The main problem is that I get no real sense of the semantic difference between |
@nicowilliams wrote:
References to code examples were already provided - see "rosettacode" refs above. As for naming - I don't see a huge problem, as manual.yml makes the distinction quite clear. As for mixing them up - well, we already have that problem because jq's If you don't like [@itchyny - Since the name |
PR #2767 adds Until recently (that is, prior to 21 June 2023), v1.6 of manual.yml was silent about Since it would still be possible to deprecate or discourage It might also be worth reflecting on the wisdom of being cautious about retroactively adding specification detail to prior versions of manual.yml, at least when there's the probability that its omission was intentional (the probability here being related to doubts about the superabundance of polymorphism). (*) dd5ce98 docs/content/manual/v1.6/manual.yml (Alex Jurkiewicz 2023-06-21 19:21:39 +1000 750) - The length of a number is its absolute value. |
whilst is like while but more conventional.