Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Curly braces

Curly braces

Scheduled Pinned Locked Moved The Lounge
hostingcloud
43 Posts 25 Posters 58 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • pkfoxP pkfox

    Are you in this camp

    void AFunc(){
    }

    or this one

    void AFunc()
    {
    }

    I'm in the second

    Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #6

    pkfox wrote:

    I'm in the second

    I second you. :-D

    "In testa che avete, Signor di Ceprano?" -- Rigoletto

    In testa che avete, signor di Ceprano?

    1 Reply Last reply
    0
    • pkfoxP pkfox

      Are you in this camp

      void AFunc(){
      }

      or this one

      void AFunc()
      {
      }

      I'm in the second

      Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

      S Offline
      S Offline
      Slacker007
      wrote on last edited by
      #7

      I distinctly remember a similar post on this site about 12 years ago. The replies were all the same then as they are today. :laugh:

      1 Reply Last reply
      0
      • pkfoxP pkfox

        Are you in this camp

        void AFunc(){
        }

        or this one

        void AFunc()
        {
        }

        I'm in the second

        Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

        Mike HankeyM Offline
        Mike HankeyM Offline
        Mike Hankey
        wrote on last edited by
        #8

        The later, is easier for me to follow.

        PartsBin an Electronics Part Organizer - An updated version available! JaxCoder.com

        1 Reply Last reply
        0
        • pkfoxP pkfox

          Are you in this camp

          void AFunc(){
          }

          or this one

          void AFunc()
          {
          }

          I'm in the second

          Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #9

          First: Java, Javascript, PHP Second: C, C++, C# Who needs braces: Python

          OriginalGriffO 1 Reply Last reply
          0
          • L Lost User

            First: Java, Javascript, PHP Second: C, C++, C# Who needs braces: Python

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #10

            Richard MacCutchan wrote:

            Who needs braces: Python

            FTFY! :laugh:

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            • pkfoxP pkfox

              Are you in this camp

              void AFunc(){
              }

              or this one

              void AFunc()
              {
              }

              I'm in the second

              Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

              R Offline
              R Offline
              Ron Anders
              wrote on last edited by
              #11

              Second.

              1 Reply Last reply
              0
              • pkfoxP pkfox

                Are you in this camp

                void AFunc(){
                }

                or this one

                void AFunc()
                {
                }

                I'm in the second

                Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

                Mircea NeacsuM Offline
                Mircea NeacsuM Offline
                Mircea Neacsu
                wrote on last edited by
                #12

                Come on!! What's next? Tabs vs spaces?

                Mircea

                M 1 Reply Last reply
                0
                • pkfoxP pkfox

                  Are you in this camp

                  void AFunc(){
                  }

                  or this one

                  void AFunc()
                  {
                  }

                  I'm in the second

                  Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

                  P Online
                  P Online
                  PIEBALDconsult
                  wrote on last edited by
                  #13

                  I reject the premise of the question.

                  1 Reply Last reply
                  0
                  • J Jacquers

                    Depends on the language. C#: Method() { } Javascrip / Typescript: function() { }

                    H Offline
                    H Offline
                    honey the codewitch
                    wrote on last edited by
                    #14

                    same. in C++ i do the latter. In C# I do the former.

                    To err is human. Fortune favors the monsters.

                    1 Reply Last reply
                    0
                    • pkfoxP pkfox

                      Are you in this camp

                      void AFunc(){
                      }

                      or this one

                      void AFunc()
                      {
                      }

                      I'm in the second

                      Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

                      S Offline
                      S Offline
                      Sanjay K Gupta
                      wrote on last edited by
                      #15

                      I prefer the first one in javascript/typescript and the second one in C#.

                      ___ ___ ___
                      |__ |_| |\ | | |_| \ /
                      __| | | | \| |__| | | /

                      1 Reply Last reply
                      0
                      • pkfoxP pkfox

                        Are you in this camp

                        void AFunc(){
                        }

                        or this one

                        void AFunc()
                        {
                        }

                        I'm in the second

                        Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

                        J Offline
                        J Offline
                        Jorgen Andersson
                        wrote on last edited by
                        #16

                        The first one wasn't invented for clarity or ease of reading, but for squeezing more text onto paper.

                        Wrong is evil and must be defeated. - Jeff Ello

                        1 Reply Last reply
                        0
                        • OriginalGriffO OriginalGriff

                          Yep. It's called "Whitesmiths": Indentation style - Wikipedia[^] It's more consistent than Allman.

                          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

                          J Offline
                          J Offline
                          Jorgen Andersson
                          wrote on last edited by
                          #17

                          That would depend on whether you consider the braces to be a part of the content or the header. If your answer is neither you should consider GNU style. ;P

                          Wrong is evil and must be defeated. - Jeff Ello

                          1 Reply Last reply
                          0
                          • pkfoxP pkfox

                            Are you in this camp

                            void AFunc(){
                            }

                            or this one

                            void AFunc()
                            {
                            }

                            I'm in the second

                            Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

                            D Offline
                            D Offline
                            den2k88
                            wrote on last edited by
                            #18

                            I used to be in the first camp, I had to adapt to MISRA rules and now I prefer the second. It's way easier to find missing braces, move braced code and reindent it, even with powerful syntax highlighting - which is not a given in most IDEs for embedded development.

                            GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                            N 1 Reply Last reply
                            0
                            • J Jacquers

                              Depends on the language. C#: Method() { } Javascrip / Typescript: function() { }

                              F Offline
                              F Offline
                              fgs1963
                              wrote on last edited by
                              #19

                              I have no opinion about braces one way or the other but I have to ask - Why use different styles in different languages? Given it's a choice it seems your personal sense of style would prefer one style all the time. No?

                              J 1 Reply Last reply
                              0
                              • F fgs1963

                                I have no opinion about braces one way or the other but I have to ask - Why use different styles in different languages? Given it's a choice it seems your personal sense of style would prefer one style all the time. No?

                                J Offline
                                J Offline
                                Jacquers
                                wrote on last edited by
                                #20

                                I generally just use what's in the specific language's style guide. It makes it easier when different developers work on a project if we stick to those.

                                T 1 Reply Last reply
                                0
                                • Mircea NeacsuM Mircea Neacsu

                                  Come on!! What's next? Tabs vs spaces?

                                  Mircea

                                  M Offline
                                  M Offline
                                  MarkTJohnson
                                  wrote on last edited by
                                  #21

                                  A POX upon Tabs.

                                  I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.

                                  Mircea NeacsuM D 2 Replies Last reply
                                  0
                                  • pkfoxP pkfox

                                    Are you in this camp

                                    void AFunc(){
                                    }

                                    or this one

                                    void AFunc()
                                    {
                                    }

                                    I'm in the second

                                    Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

                                    S Offline
                                    S Offline
                                    Single Step Debugger
                                    wrote on last edited by
                                    #22

                                    I'm in this camp

                                    void AFunc()
                                    {
                                    }

                                    And for short/inline statements in this one:

                                    void AFunc() {}

                                    I never mix them.

                                    There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                                    1 Reply Last reply
                                    0
                                    • D den2k88

                                      I used to be in the first camp, I had to adapt to MISRA rules and now I prefer the second. It's way easier to find missing braces, move braced code and reindent it, even with powerful syntax highlighting - which is not a given in most IDEs for embedded development.

                                      GCS/GE d--(d) s-/+ a C+++ U+++ P-- L+@ E-- W+++ N+ o+ K- w+++ O? M-- V? PS+ PE Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- r+++ y+++*      Weapons extension: ma- k++ F+2 X

                                      N Offline
                                      N Offline
                                      Nelek
                                      wrote on last edited by
                                      #23

                                      exactly.

                                      M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                      1 Reply Last reply
                                      0
                                      • pkfoxP pkfox

                                        Are you in this camp

                                        void AFunc(){
                                        }

                                        or this one

                                        void AFunc()
                                        {
                                        }

                                        I'm in the second

                                        Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

                                        N Offline
                                        N Offline
                                        Nelek
                                        wrote on last edited by
                                        #24

                                        In the second one, even when an If has only one command to be executed.

                                        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

                                        1 Reply Last reply
                                        0
                                        • pkfoxP pkfox

                                          Are you in this camp

                                          void AFunc(){
                                          }

                                          or this one

                                          void AFunc()
                                          {
                                          }

                                          I'm in the second

                                          Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP

                                          G Offline
                                          G Offline
                                          godfetish
                                          wrote on last edited by
                                          #25

                                          The only sane format is:

                                          void Afunc()
                                          {
                                          }

                                          Why #1: Because half the non-curly scoped languages out there use words or other symbols for marking scope, and BEGIN just doesn't look right at the end of the line! Why #2: Java version 1.1 (the first language I used and learned that trailed the curly brace in books) was so horrible, it gave me one more thing to hate! Why #3: Other than using some automated reformatting that kicks lines to the right or left, I find it very difficult to find missing curly braces in some logic. Matched ones line up very clearly. If they trail the line, when things get a few indents deep, the code becomes hard to read and finding that one line you inserted outside of them takes more time than just begin clear the first time. So, always on its own line!

                                          The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.

                                          K T 2 Replies Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups