News for hackers. Stuff that matters.
Re:3D Game Shaders for Beginners by barbwire on Monday May 13, 2019 @12:05AM (#19896356)
Am I just out of touch with what the kids today are doing, or is this formatting really as bonkers as it seems?

  int main
    ( int argc
    , char *argv[]
    ) {
  
    // ...
  
    LColor backgroundColor =
      LColor
        ( generateLightColorPart(207, 1)
        , generateLightColorPart(154, 1)
        , generateLightColorPart(108, 1)
        , 1
        );
  
    // ...
  
  }
I can (sort of) see that this makes it easy to comment out parameters - except for the first one...
Re:3D Game Shaders for Beginners by kragen on Monday May 13, 2019 @04:51AM (#19897275)
In languages that don't allow trailing commas, I prefer this comma-first style. It makes it easy to avoid missing or extra commas, which shortens my feedback loop a bit. But I usually don't use it, because a lot of people react the way you do, and I want you to be able to read and enjoy my code despite your irrational and bizarrely extreme prejudice.
Re:3D Game Shaders for Beginners by danbolt on Monday May 13, 2019 @08:26PM (#19905540)
I had never really thought about commas that way, but I can totally get why someone would want to use this style now. Thank you for taking the time to explain it!
Re:3D Game Shaders for Beginners by p1necone on Monday May 13, 2019 @01:09AM (#19896562)
I've noticed this formatting in sql scripts before too - the biggest benefit I see is making source control diffs only show one line changed rather than two when adding/removing lines.
Re:3D Game Shaders for Beginners by barbwire on Monday May 13, 2019 @03:13AM (#19896926)
Unless you're inserting as the first line ...
Re:3D Game Shaders for Beginners by Ace17 on Monday May 13, 2019 @08:23AM (#19898537)
The benefit (compared to more classic formatting) only occurs if you're inserting at the end of the argument list.

If adding stuff to the end of a class or of an argument list is your most frequent case, you might have a software design problem.

Re:3D Game Shaders for Beginners by edflsafoiewq on Monday May 13, 2019 @03:05AM (#19896904)
Is that a benefit?
Re:3D Game Shaders for Beginners by PudgePacket on Monday May 13, 2019 @03:09AM (#19896911)
Yes. When you git blame a line you won't get a commit just adding/removing a comma changing on that line.
Re:3D Game Shaders for Beginners by newaccoutnas on Monday May 13, 2019 @04:19AM (#19897148)
Some languages/DSL's allow for a comma at the end of the list too, thereby getting the same result but without the slightly strange comma at the start of the line. Adding additional lines is simple then and doesn't cause the line above to be pulled in to any git action
Re:3D Game Shaders for Beginners by PetahNZ on Monday May 13, 2019 @05:04AM (#19897328)
Maybe git blame should get better.
Re:3D Game Shaders for Beginners by dahart on Monday May 13, 2019 @10:25AM (#19899527)
What’s bonkers specifically? Is the the leading commas, alignment, one identifier per line, capitalization, long names, same line braces, something else?

FWIW, everything seen here has options in Clang Format: https://clang.llvm.org/docs/ClangFormatStyleOptions.html

Personally, I like what this looks like. Leading commas are nice in situations where the first argument is fixed, but the remaining arguments move a lot while I’m tweaking & refactoring. I also like leading operators in long multi line math expressions, it’s easier to see at a glance how everything is combined when the operators are in front. I also like seeing arguments aligned, it’s easier to spot mistakes, easier to move things around, easier to use column selection, etc.

I rarely actually use the formatting I like because at work my team uses clang format so we’re standardized. Despite whatever formatting opinions I like, I love not arguing about formatting and having the formatter dictate and handle it for everyone.

Re:3D Game Shaders for Beginners by FPGAhacker on Monday May 13, 2019 @12:56AM (#19896519)
I write this way to make it easier to see when I’ve missed a comma, and also for editor macros.

I’ll often reformat when I’m done so it fits our code review style.

Also I’m usually working systemverilog so 5-10 parameters are common and 50 or more isn’t rare.

Re:3D Game Shaders for Beginners by abower on Monday May 13, 2019 @08:05PM (#19905390)
If you do a lot of adhoc sql with an editer that supports multiline editing, it allows for pasting in big lists of text and quickly formatting it, trailing commas and ragged edge right data suck to edit in bulk.
Re:3D Game Shaders for Beginners by zengid on Monday May 13, 2019 @08:24AM (#19898546)
I see that occasionally in my works codebase. I don't mind it so much. Sometimes I'll see

    If(predicate
       && nextPredicate
       && lastPredicate)
    {
        DoStuff();
    }
Which I don't mind but also don't write. However, I do prefer ternary expressions like

    int someNum = somePred
        ? firstVal + 42
        : 1000;
Re:3D Game Shaders for Beginners by Inityx on Monday May 13, 2019 @01:22AM (#19896595)
It's a hacky workaround for languages that don't support trailing commas
Re:3D Game Shaders for Beginners by Guthur on Monday May 13, 2019 @04:38PM (#19903702)
And more widely; languages that burden the programmer with such extraneous grammar in the first place.
Re:3D Game Shaders for Beginners by jchw on Monday May 13, 2019 @12:11AM (#19896377)
Reminds me of how Elm lists are formatted; I have a hunch it may be something more common in Haskell, but that's pretty much a shot in the dark.
Re:3D Game Shaders for Beginners by whateveracct on Monday May 13, 2019 @07:47PM (#19905260)
Yeah this is Haskell formatting
Re:3D Game Shaders for Beginners by chasingthewind on Monday May 13, 2019 @11:49AM (#19900470)
The part that has me twitching are the magic numbers in the calls to generateLightColorPart :P