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. Other Discussions
  3. The Back Room
  4. Stupid Programming Standards -- 80 chars?

Stupid Programming Standards -- 80 chars?

Scheduled Pinned Locked Moved The Back Room
visual-studiohelpquestioncareer
21 Posts 13 Posters 0 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.
  • L Lost User

    My personal pet hate is every function must have one and only one return statement

    C Offline
    C Offline
    Christian Graus
    wrote on last edited by
    #9

    See, while I disagree with this as a requirement, 99% of my functions do have only one return statement, it is a good principle to aim for, what's wrong is when it becomes a hard and fast rule and you have to write code around the rule.

    Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

    L 1 Reply Last reply
    0
    • C Christian Graus

      See, while I disagree with this as a requirement, 99% of my functions do have only one return statement, it is a good principle to aim for, what's wrong is when it becomes a hard and fast rule and you have to write code around the rule.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

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

      Christian Graus wrote:

      See, while I disagree with this as a requirement, 99% of my functions do have only one return statement, it is a good principle to aim for, what's wrong is when it becomes a hard and fast rule and you have to write code around the rule.

      What I really disliked about this rule was code that should look like this void Function(int param) { if(param < 0) return; //lots more code } now becomes void Function(int param) { if(param >= 0) { //lots of code } //nothing here } I found that often the "real work" of the function would be many levels of indentation deep

      S D 2 Replies Last reply
      0
      • C CurtD

        As a contractor/consultant, I have worked in a lot of places over 25 years. Without fail, everyone of them has had a rule that source code should not exceed 80 chars per line. I've always asked if this is because they are backing everything up to punched cards. Back in the Win 3.1 days, they would tell me that there was always some asshole who used DOS edit (or even edlin) for writing code. I always thought this was a good reason to suggest that they pursue another career. Now in the VS 2005 IDE, with my widescreen monitor, even with some toolbars added to the sides, 80 chars doesn't even go half way across my screen. And yet, we still have the 80 char rule (which I completely ignore). Hell, even the mainframe printers from the 1960's would print 120 chars (I think -- that was a lot of beers ago, but I know it was > 80). If you are still writing code in an 80 char mode editor or using a dot matrix printer, there are plenty of jobs at McDonalds (or the Smithsonian perhaps). People need to stop blindly following rules that make no sense. This is an especially bad problem with computer nerds. If no one can explain why a rule exists, then get rid of it and ignore it until someone does.

        D Offline
        D Offline
        DaveX86
        wrote on last edited by
        #11

        CurtD wrote:

        Hell, even the mainframe printers from the 1960's would print 120 chars

        132 chars is what I remember for the 'wide format' dot matrix printers. Whatever makes code easier to read and follow is the rule I go by.

        1 Reply Last reply
        0
        • C CurtD

          As a contractor/consultant, I have worked in a lot of places over 25 years. Without fail, everyone of them has had a rule that source code should not exceed 80 chars per line. I've always asked if this is because they are backing everything up to punched cards. Back in the Win 3.1 days, they would tell me that there was always some asshole who used DOS edit (or even edlin) for writing code. I always thought this was a good reason to suggest that they pursue another career. Now in the VS 2005 IDE, with my widescreen monitor, even with some toolbars added to the sides, 80 chars doesn't even go half way across my screen. And yet, we still have the 80 char rule (which I completely ignore). Hell, even the mainframe printers from the 1960's would print 120 chars (I think -- that was a lot of beers ago, but I know it was > 80). If you are still writing code in an 80 char mode editor or using a dot matrix printer, there are plenty of jobs at McDonalds (or the Smithsonian perhaps). People need to stop blindly following rules that make no sense. This is an especially bad problem with computer nerds. If no one can explain why a rule exists, then get rid of it and ignore it until someone does.

          F Offline
          F Offline
          FyreWyrm
          wrote on last edited by
          #12

          You get 80 characters? We only get 72. Seriously, only 72. I think it's so the code can easily be read by the blind (my boss). He has a 20" CRT monitor and uses 800 x 600 resolution so he can easily see what's on the screen.

          1 Reply Last reply
          0
          • B BoneSoft

            I just love those JavaScripter's that like to remove all whitespace as a cheap form of obfuscation.


            Try code model generation tools at BoneSoft.com.

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #13

            It's also a cheap form of compression. Hey, bytes matter...

            1 Reply Last reply
            0
            • L Lost User

              Christian Graus wrote:

              See, while I disagree with this as a requirement, 99% of my functions do have only one return statement, it is a good principle to aim for, what's wrong is when it becomes a hard and fast rule and you have to write code around the rule.

              What I really disliked about this rule was code that should look like this void Function(int param) { if(param < 0) return; //lots more code } now becomes void Function(int param) { if(param >= 0) { //lots of code } //nothing here } I found that often the "real work" of the function would be many levels of indentation deep

              S Offline
              S Offline
              Shog9 0
              wrote on last edited by
              #14

              Exactly. It's a good guideline, in that returns deep in the bowels of the code just make it harder to follow... but common sense dictates there is a time and a place for just getting the hell out of a function now.

              J 1 Reply Last reply
              0
              • C CurtD

                As a contractor/consultant, I have worked in a lot of places over 25 years. Without fail, everyone of them has had a rule that source code should not exceed 80 chars per line. I've always asked if this is because they are backing everything up to punched cards. Back in the Win 3.1 days, they would tell me that there was always some asshole who used DOS edit (or even edlin) for writing code. I always thought this was a good reason to suggest that they pursue another career. Now in the VS 2005 IDE, with my widescreen monitor, even with some toolbars added to the sides, 80 chars doesn't even go half way across my screen. And yet, we still have the 80 char rule (which I completely ignore). Hell, even the mainframe printers from the 1960's would print 120 chars (I think -- that was a lot of beers ago, but I know it was > 80). If you are still writing code in an 80 char mode editor or using a dot matrix printer, there are plenty of jobs at McDonalds (or the Smithsonian perhaps). People need to stop blindly following rules that make no sense. This is an especially bad problem with computer nerds. If no one can explain why a rule exists, then get rid of it and ignore it until someone does.

                S Offline
                S Offline
                Shog9 0
                wrote on last edited by
                #15

                I set up VS to draw guidelines at 80 and 120 chars. I stop at or around 80 for comments, and try to stay below 120 for code. Generally, this keeps it easy to read - i don't care how wide your screen is, i doubt your field of vision is really wide enough to take in much more than that without a lot of left-right scanning. And, i do like to print out code now and then, without having to wrap lines or shrink the font down.

                D 1 Reply Last reply
                0
                • C CurtD

                  As a contractor/consultant, I have worked in a lot of places over 25 years. Without fail, everyone of them has had a rule that source code should not exceed 80 chars per line. I've always asked if this is because they are backing everything up to punched cards. Back in the Win 3.1 days, they would tell me that there was always some asshole who used DOS edit (or even edlin) for writing code. I always thought this was a good reason to suggest that they pursue another career. Now in the VS 2005 IDE, with my widescreen monitor, even with some toolbars added to the sides, 80 chars doesn't even go half way across my screen. And yet, we still have the 80 char rule (which I completely ignore). Hell, even the mainframe printers from the 1960's would print 120 chars (I think -- that was a lot of beers ago, but I know it was > 80). If you are still writing code in an 80 char mode editor or using a dot matrix printer, there are plenty of jobs at McDonalds (or the Smithsonian perhaps). People need to stop blindly following rules that make no sense. This is an especially bad problem with computer nerds. If no one can explain why a rule exists, then get rid of it and ignore it until someone does.

                  V Offline
                  V Offline
                  V 0
                  wrote on last edited by
                  #16

                  We don't have that rule here... :-) Feel free to apply :laugh:

                  V.
                  Stop smoking so you can: Enjoy longer the money you save. Moviereview Archive

                  1 Reply Last reply
                  0
                  • C CurtD

                    As a contractor/consultant, I have worked in a lot of places over 25 years. Without fail, everyone of them has had a rule that source code should not exceed 80 chars per line. I've always asked if this is because they are backing everything up to punched cards. Back in the Win 3.1 days, they would tell me that there was always some asshole who used DOS edit (or even edlin) for writing code. I always thought this was a good reason to suggest that they pursue another career. Now in the VS 2005 IDE, with my widescreen monitor, even with some toolbars added to the sides, 80 chars doesn't even go half way across my screen. And yet, we still have the 80 char rule (which I completely ignore). Hell, even the mainframe printers from the 1960's would print 120 chars (I think -- that was a lot of beers ago, but I know it was > 80). If you are still writing code in an 80 char mode editor or using a dot matrix printer, there are plenty of jobs at McDonalds (or the Smithsonian perhaps). People need to stop blindly following rules that make no sense. This is an especially bad problem with computer nerds. If no one can explain why a rule exists, then get rid of it and ignore it until someone does.

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #17

                    You need a limit somewhere - I agree that a hard limit of 80 is a little low, but I'm working with a code generation tool at the moment - it generates some lines of with more than 400 characters - that's a bit on the long side :-) Looking at *my* code, my hard limit seems to be about 150 characters, but I try to use multi-line and indentation if a statement goes over about 100 characters. I just try and make the code reasonably readable, without unnecessarily fragmented lines.

                    1 Reply Last reply
                    0
                    • S Shog9 0

                      Exactly. It's a good guideline, in that returns deep in the bowels of the code just make it harder to follow... but common sense dictates there is a time and a place for just getting the hell out of a function now.

                      J Offline
                      J Offline
                      Jorgen Sigvardsson
                      wrote on last edited by
                      #18

                      Especially from the function dodge() ;)

                      -- Kein Mitleid Für Die Mehrheit

                      1 Reply Last reply
                      0
                      • L Lost User

                        Christian Graus wrote:

                        See, while I disagree with this as a requirement, 99% of my functions do have only one return statement, it is a good principle to aim for, what's wrong is when it becomes a hard and fast rule and you have to write code around the rule.

                        What I really disliked about this rule was code that should look like this void Function(int param) { if(param < 0) return; //lots more code } now becomes void Function(int param) { if(param >= 0) { //lots of code } //nothing here } I found that often the "real work" of the function would be many levels of indentation deep

                        D Offline
                        D Offline
                        Dan Neely
                        wrote on last edited by
                        #19

                        the defensive coding against that sort of standard is to move all the validation into a separate function, so that you only have level of indent. bool FooValidator(...) { bool retVal = true; reval &= cond1; reval &= cond2; ... return retVal; } void Foo(...) { if (ValidateFoo(..)) { ... } }

                        1 Reply Last reply
                        0
                        • S Shog9 0

                          I set up VS to draw guidelines at 80 and 120 chars. I stop at or around 80 for comments, and try to stay below 120 for code. Generally, this keeps it easy to read - i don't care how wide your screen is, i doubt your field of vision is really wide enough to take in much more than that without a lot of left-right scanning. And, i do like to print out code now and then, without having to wrap lines or shrink the font down.

                          D Offline
                          D Offline
                          Dan Neely
                          wrote on last edited by
                          #20

                          Where is that option at?

                          -- Join the Campaign to Help Stamp Out and Abolish Redundancy The preceding is courtesy of the Bureau of Unnecessarily Redundant Repetition Department.

                          S 1 Reply Last reply
                          0
                          • D Dan Neely

                            Where is that option at?

                            -- Join the Campaign to Help Stamp Out and Abolish Redundancy The preceding is courtesy of the Bureau of Unnecessarily Redundant Repetition Department.

                            S Offline
                            S Offline
                            Shog9 0
                            wrote on last edited by
                            #21

                            Registry hack: http://blogs.msdn.com/saraford/archive/2004/05/05/257953.aspx[^]

                            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