Skip to content

Development: code style and guidelines

Nico Williams edited this page Aug 14, 2015 · 2 revisions

C Style

It's pretty simple:

  • indent with two spaces
  • lines can be very long, so your $EDITOR had better handle it
  • align indented continuations of function arguments on the column after the opening parenthesis
  • no whitespace after casts
  • ...

TODO: Finish this. Mind you, it's somewhat free-form style, but as always, when in Rome...

C function design guidelines

  • functions should consume a reference for each and every jv input argument
  • use jv in preference to C types whenever possible

jq Style

Most jq programs and functions are very short and require little in the way of style.

But jq programs and functions can be large enough to require splitting across multiple lines, in which case the preferred style is: .

Discussion

jq is a lot like SQL when it comes to styling multi-line programs. Where should ... | ... be split? Should the | be left on the end of the first line or the beginning of the next? This is a matter of taste, but if one leaves the | on the end of the first line then one should line up all the |s at the same level of parenthesis nesting.

When should one indent? | should not require indenting the right side. But perhaps the first continuation should be indented.

...

Clone this wiki locally