• Gork@lemm.ee
    link
    fedilink
    arrow-up
    35
    ·
    8 months ago

    All of those are heretical. The one True Language is Brainfuck, where the coding syntax for Hello World is

    ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

  • blindsight@beehaw.org
    link
    fedilink
    arrow-up
    34
    ·
    edit-2
    8 months ago

    idk, Allman is very readable. Easy to scan vertically to find the matching open brace. Not quite as vertically-space efficient as the best way, but it’s not offensive.

      • blindsight@beehaw.org
        link
        fedilink
        arrow-up
        4
        ·
        8 months ago

        I literally don’t understand. I’ve read your comment several times and I don’t know what you’re talking about. Sorry!

        Did you think I was saying that made Allman better than the best way? Because it’s easy to scan vertically the best way, too. It’s just also easy with Allman, so it’s not offensive.

    • hardware26@discuss.tchncs.de
      link
      fedilink
      arrow-up
      2
      ·
      8 months ago

      In my first ever programming class textbook was using Allman. Probably for this reason, it is easy for a beginner to match braces. It is a lot loss common industry to my knowledge.

  • Solrac@lemmy.world
    link
    fedilink
    arrow-up
    31
    ·
    8 months ago

    Finally, someone understands that Allman is not that great, and that Kernighan & Ritchie is the way to go. Also, Haskell, my guy, you good? Lisp, are you ok? Do I need to call your parents?

    • gerryflap@feddit.nl
      link
      fedilink
      arrow-up
      2
      ·
      8 months ago

      I’ve written Haskell quite a bit, and I don’t fully understand why this is called Haskell style. Haskell code looks nothing like this, the syntax is completely different. For Haskell’s syntax I think it works fine, because I never noticed something weird. But this code in “Haskell style” looks absolutely insane

  • Aedis@lemmy.world
    link
    fedilink
    arrow-up
    23
    ·
    8 months ago

    Tell me you’re a Java developer without telling me you’re a Java developer.

    • kryptonianCodeMonkey@lemmy.world
      link
      fedilink
      arrow-up
      17
      ·
      edit-2
      8 months ago

      All line breaks. Just one tower of code.

      class
      HelloWorld
      {
      public
      static
      void
      main(String[]
      args)
      {
      System.out.println("Hello,
      World!");
      }
      }
      
      • cassie 🐺@lemmy.blahaj.zone
        link
        fedilink
        English
        arrow-up
        7
        ·
        edit-2
        8 months ago

        as always, c++ lets us do better in breathtakingly elegant fashion:

        #\
        i\
        n\
        c\
        l\
        u\
        d\
        e\
         \ 
        &lt;\
        i\
        o\
        s\
        t\
        r\
        e\
        a\
        m\
        >
        

        finishing out hello world is left as an exercise to the reader, but the advantages and superior performance of this format should be obvious

        • 7heo@lemmy.ml
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          8 months ago

          Hear me out: brainfuck, but with parentheses only.

          >    )))
          <    (((
          +    ())
          -    (()
          .    ()(
          ,    )()
          [    )((
          ]    ))(
          

          Hello world example:

          ()))(((()(())))(())(())))))()))))(()
          (()(()(()(()(((((())(((((()(()((((()
          (()(()))()))(()()()))))))))())()()))
          )))()(()(())())()))((()()))))(((((((
          ((((((()(())())())()((()(()(()(()(()
          (()()((((((((()()())))))))))))())()(
          

          Ancient aliens meme with the caption "LIPS!!"

          Python transpiler:

          #!/usr/bin/env python
          """Lipsfuck to brainfuck transpiler"""
          
          from sys import stdin
          
          OPS = {")))": '>', "(((": '<',
                 "())": '+', "(()": '-',
                 "()(": '.', ")()": ',',
                 ")((": '[', "))(": ']'}
          
          
          def main():
              """Obvious main procedure"""
              _d = ''.join(stdin.readlines()).rstrip('\n')
              for _op in [_d[x:x+3] for x in
                          range(0, int(len(_d)), 3)]:
                  print(OPS[_op], end='')
              print()
          
          
          if __name__ == "__main__":
              main()
          
    • p1mrx@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      8 months ago

      GNU style is logical, because braces are syntactically a single statement:

      while (x == y)
        func1();  // can be replaced by { ... }
      

      However, I prefer to entirely avoid unbraced single statements after while/if:

      while (x == y) {
        func1();  // easy to add func2(); later
      }
      

      Although this is ok when it fits:

      while (x == y) func1();  // brevity!
      
  • Psythik@lemmy.world
    link
    fedilink
    arrow-up
    10
    ·
    8 months ago

    If you have ADHD, your coding style is a combination of all of these, and sometimes none of the above.

  • barsoap@lemm.ee
    link
    fedilink
    arrow-up
    8
    ·
    edit-2
    8 months ago

    Noone writes Haskell like that. People generate Haskell like that because layout syntax is a fickle beast to generate and outputting braces means you can make mistakes in layout without breaking things, the way the braces and semicolons are output emphasise how they actually don’t matter, they’re also easy to delete in a text editor.

    Also it matches up with other Haskellisms, e.g. lists:

    let foo = [ bar
              , baz
              , quux
              ]
    

    See how it’s immediately apparent that you didn’t miss a single comma? It’s also trivial to match up opening and closing brackets like that, even in deeply nested situations.

    Not doing that is actually my main pet peeve with Rust’s standard formatting.