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. Programming style

Programming style

Scheduled Pinned Locked Moved The Lounge
c++architecture
46 Posts 27 Posters 4 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.
  • C Christian Graus

    As a rule, I like to have one exit point for functions, but I sometimes make an exception for initial state checks. Which do you prefer Button btn = sender as Button; if (btn != null) { } OR Button btn = sender as Button; if (btn == null) return;

    Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

    E Offline
    E Offline
    ed welch
    wrote on last edited by
    #41

    The secound one is handy if you have a lot of nested if-then-else statements - it avoids the inner most code block being indented so much that it runs of the end of the screen

    1 Reply Last reply
    0
    • P Paul Conrad

      John Simmons / outlaw programmer wrote:

      Some of the code I've had to maintain over the last three years had functions in it that exceeded 500 lines, and some files exceeded 6000 lines.

      That is way too excessive. Gotta stick to it being able to fit on the screen all at once. Hope the original coder doesn't work there anymore...

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #42

      Paul Conrad wrote:

      Hope the original coder doesn't work there anymore.

      He dopes, but it doesn't matter. I turned in my two-week notice last week. :)

      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

      P 1 Reply Last reply
      0
      • realJSOPR realJSOP

        Paul Conrad wrote:

        Hope the original coder doesn't work there anymore.

        He dopes, but it doesn't matter. I turned in my two-week notice last week. :)

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #43

        John Simmons / outlaw programmer wrote:

        He dopes, but it doesn't matter.

        Yeah, it does. People on dope can't code...

        "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

        1 Reply Last reply
        0
        • C Christian Graus

          As a rule, I like to have one exit point for functions, but I sometimes make an exception for initial state checks. Which do you prefer Button btn = sender as Button; if (btn != null) { } OR Button btn = sender as Button; if (btn == null) return;

          Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

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

          I like the second one. With the first style I often find I end up with code like this if(something) { ... if(somethingelse) { ... if(anotherthing) { DoSomthingUseful(); } } }

          1 Reply Last reply
          0
          • C Christian Graus

            As a rule, I like to have one exit point for functions, but I sometimes make an exception for initial state checks. Which do you prefer Button btn = sender as Button; if (btn != null) { } OR Button btn = sender as Button; if (btn == null) return;

            Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            T Offline
            T Offline
            Todd Smith
            wrote on last edited by
            #45

            I prefer the 1st one since 1) its easier to debug w/one exit point 2) its easier to enforce.

            Todd Smith

            1 Reply Last reply
            0
            • C Christian Graus

              As a rule, I like to have one exit point for functions, but I sometimes make an exception for initial state checks. Which do you prefer Button btn = sender as Button; if (btn != null) { } OR Button btn = sender as Button; if (btn == null) return;

              Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

              P Offline
              P Offline
              Phil Harding
              wrote on last edited by
              #46

              Second style usually, if the method/function is short, maybe I'll go for the first. Sometimes I just flip a coin :jig:


              - "I'm not lying, I'm just writing fiction with my mouth"

              Phil Harding.
              myBlog [^] | mySite [^]

              1 Reply 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