News for hackers. Stuff that matters.
Re:Delimiter-first code by TrianguloY on Friday December 09, 2022 @06:54AM (#33920294)
Other "forced" examples:

    result = a==1
          || b==2
          || c==3
          ;
Vs

    result = a==1 ||
             b==2 ||
             c==3 ;
and

    result = data
             .getA()
             .getB()
             .getC()
             ;
Vs

    result = data.
               getA().
               getB().
               getC();
             
Personally I prefer the first examples, because for me it's easier to "group" the lines.
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)
Re:Delimiter-first code by dspillett on Friday December 09, 2022 @07:33AM (#33920541)
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