• bort@feddit.de
      link
      fedilink
      arrow-up
      28
      ·
      edit-2
      9 months ago

      Allman if the condition is very long

      while(isSomething
          && isSomethingElse
          && nFoo < 10)
      {
          bla();
          bla();
      }
      

      vs

      while(isSomething
          && isSomethingElse
          && nFoo < 10) {
          bla();
          bla();
      }
      
      • 9point6@lemmy.world
        link
        fedilink
        arrow-up
        54
        ·
        9 months ago

        Hmm, I think the condition gets newlined and you K&R on the closing parenthesis IMO:

        while (
            isSomething 
            &amp;&amp; isSomethingElse
            &amp;&amp; nFoo &lt; 10
        ) {
            blah();
            blah();
        }
        

        You could also keep isSomething on the first line too, but I think it’s nice to keep the whole multiline condition at the same indent width

    • /home/pineapplelover@lemm.ee
      link
      fedilink
      arrow-up
      3
      ·
      9 months ago

      Isn’t Java like this? Everybody I know who codes java does it like this and I’ve been trying to follow along despite it looking stupid.

  • Onlytanner@lemmy.world
    link
    fedilink
    arrow-up
    33
    ·
    9 months ago

    I had to look this up to verify that these are not only real styles, but there are/were some individuals had the gall to make other people consider these awful indentation styles. Of course it was only the C gods themselves to actually come up with something both readable and aesthetically pleasing.

    All joking aside, I’d have to imagine some of these make more sense when applied to languages other than C. Even still, there is clearly one true winner in my book.

    • azertyfun@sh.itjust.works
      link
      fedilink
      arrow-up
      6
      ·
      9 months ago

      Every C-inspired language with curly braces (which is a lot of them) that I know uses some variation on K&R/Allman.
      Golang straight up enforces the “K&R” style and doesn’t recognize a curly brace on a new line. I don’t know of a JSON prettifier that doesn’t use “K&R” style either.

      Unless you mean that the Haskell/Lisp styles make more sense in Haskell/Lisp, which, yeah, obviously. Hopefully no-one actually writes C code like that.

  • amotio@lemmy.world
    link
    fedilink
    arrow-up
    30
    ·
    9 months ago

    I was for long a long time using Kernighan style, but recently switched to Allman. Everything is suddenly more readable. It’s a journey.

  • Child Eater@iusearchlinux.fyi
    link
    fedilink
    arrow-up
    5
    ·
    9 months ago

    I was a K&R guy forever but I’ve been learning C++ recently (I know…) and I’ve found myself gravitating towards Allman more and more

  • Wirlocke@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    5
    ·
    edit-2
    9 months ago

    I feel like I’d use Allman for large blocks of code (though in those situations it’s probably better to stick the code in a function first) and I’d use K&R for 1 or 2 lines of code (like calling a function).

  • Camelbeard@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    9 months ago

    I’m used to K&R so no real need to switch, also my IDE by default formats in that style. Allman also looks fine, most of the others just seem to make code less readable.

  • SpunkyMcGoo@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    9 months ago

    hot take: python using whitespace to format rather than curly braces and semicolons is cool and epic, actually

  • Boo@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    3
    ·
    9 months ago

    I formatted all my C code in High School with the GNU style. I’m not sure my teacher even read the code :P

    I mostly write Lisp today, but that GNU style still has a special place in my heart. As long as it’s automatically formatted, I’m fine with whatever style, though.