Re:Delimiter-first code
by TrianguloY on Friday December 09, 2022 @06:54AM
(#33920294)
Other "forced" examples:
Vs
and
Vs
Personally I prefer the first examples, because for me it's easier to "group" the lines.
[ Parent
| on HN ]
Re:Delimiter-first code
by tasty_freeze on Friday December 09, 2022 @10:58AM
(#33922720)
I write a lot of verilog code, and most of its operators are the same a for C. Your first example doesn't highlight the real benefit of its style because all of your items are the same length. Here is a better example:
foo = here_is_some_logical_condition ||
and_another ||
(this_term && that_term) ||
exception_case;
vs foo = here_is_some_logical_condition
|| and_another
|| (this_term && that_term)
|| exception_case;
Re:Delimiter-first code
by sweetsocks21 on Friday December 09, 2022 @11:29AM
(#33923153)
This delimiter first pattern is used a lot in Ocaml code as well:
Records: https://github.com/janestreet/base/blob/master/src/avltree.m...
If statements: https://github.com/janestreet/base/blob/master/src/string.ml...
Lists: https://github.com/janestreet/base/blob/master/src/string.ml...
Function calls: https://github.com/janestreet/base/blob/master/src/string.ml...
Type definitions: https://github.com/janestreet/base/blob/master/src/array.ml#...
It's not always used, shorter snippets tend to be all on one line.
I tend to use that sort of layout, particularly the comma-first example shown in the article for SQL and JSON. It makes moving things around less error prone (no need to worry about where the ; is then you reorder or add to or remove from the end of a list) and makes diffs cleaner between versions for the same reason. And I feel it just seems clearer. Some people seem to hate it with a passion though.
Re:Delimiter-first code
by TrianguloY on Friday December 09, 2022 @05:58PM
(#33927562)
The issue with that layout (and with my examples) is that the first element is the odd one, and you can't reorder it. I think it's better this way (usually the first different is special, and also you usually add things at the end) but I prefer a trailing comma over the comma at the left. A leading comma, like the article discuss, would be an nice addition indeed