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. Coding standards?

Coding standards?

Scheduled Pinned Locked Moved The Lounge
comquestion
27 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.
  • T Tim Smith

    No exception handling Woohoo, at least he did one thing right. ;) Other than the fact that I can't use exception handling in WinCE, I find that most people don't have a clue how to properly use it. They just sort of throw it in because they think they should. Then don't really do anything with it. There are the cases where some moron decided that an exception was MUCH better than just returning a simple failure flag. Whine whine whine :) Tim Smith Descartes Systems Sciences, Inc.

    N Offline
    N Offline
    Not Active
    wrote on last edited by
    #7

    I'll agree that a lot don't know how to properly use SEH, but in a system that is supposed to be 99.999% reliable (contract requirements), not using any is just outrageously poor design.

    T 1 Reply Last reply
    0
    • N Not Active

      I'll agree that a lot don't know how to properly use SEH, but in a system that is supposed to be 99.999% reliable (contract requirements), not using any is just outrageously poor design.

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #8

      Actually, I totally disagree. exceptions != reliability. (But I will say that in many cases exceptions can make your life easier.) Of course, software controlled exceptions are ok.

      if (i != 22)
      throw CBadBoyException ();

      However, that 'can' be replaced by.

      if (i != 22)
      return false;

      Of course, this model has all sorts of drawbacks. The first one being that if the programmer doesn't check return values, then returning false doesn't do a damn bit of good either. However, exceptions have the same type of pitfalls. One of the basic theories is that during a given operation, if an exception is thrown, then all of the operation is rolled back. Thus, the operation is basically atomic. (i.e. An exception during a std::map operation will leave the map valid and in the prior state.) However, programmers have a bad habit of not properly checking for exception when partial operations need to be rolled back. Then we get into other exceptions such as out of memory. Now in theory, a program should survive and out of memory exception and handle it properly. However, in the real world, there are many cases where the program can't function properly without the memory. Then it becomes a question of does the program abend gracefully. The final type of exception is a hardware exception such as an access violation. Many people think they can continue from a general out of the blue access violation. But realistically, can the application be trusted to operate reasonable after that type of failure? Only god knows what data might have been damaged. This is especially critical in mission critical applications. Your program has just faulted, do you really trust it to continue to control equipment that might put a person's life in danger. Here again, it becomes a question of dead the program abend gracefully. In general, exceptions shouldn't happen except for well defined and expected cases. An access violation is still a bug, and the bug must be corrected. If for one don't trust an exception handler to try and 'fix' an access violation. Tim Smith Descartes Systems Sciences, Inc.

      N 1 Reply Last reply
      0
      • N Not Active

        #ifdef NULL #undef NULL #define NULL 0 Why did you do this? Because we wanted to define what NULL was. :confused:

        E Offline
        E Offline
        Erik Funkenbusch
        wrote on last edited by
        #9

        Actually, this is valid code. NULL is different between C and C++. In C, NULL is (void*)0, in C++ it's just 0. If you have code that mixes the two, you might well want to make sure what is defined. -- Where are we going? And why am I in this handbasket?

        1 Reply Last reply
        0
        • T Tim Smith

          Actually, I totally disagree. exceptions != reliability. (But I will say that in many cases exceptions can make your life easier.) Of course, software controlled exceptions are ok.

          if (i != 22)
          throw CBadBoyException ();

          However, that 'can' be replaced by.

          if (i != 22)
          return false;

          Of course, this model has all sorts of drawbacks. The first one being that if the programmer doesn't check return values, then returning false doesn't do a damn bit of good either. However, exceptions have the same type of pitfalls. One of the basic theories is that during a given operation, if an exception is thrown, then all of the operation is rolled back. Thus, the operation is basically atomic. (i.e. An exception during a std::map operation will leave the map valid and in the prior state.) However, programmers have a bad habit of not properly checking for exception when partial operations need to be rolled back. Then we get into other exceptions such as out of memory. Now in theory, a program should survive and out of memory exception and handle it properly. However, in the real world, there are many cases where the program can't function properly without the memory. Then it becomes a question of does the program abend gracefully. The final type of exception is a hardware exception such as an access violation. Many people think they can continue from a general out of the blue access violation. But realistically, can the application be trusted to operate reasonable after that type of failure? Only god knows what data might have been damaged. This is especially critical in mission critical applications. Your program has just faulted, do you really trust it to continue to control equipment that might put a person's life in danger. Here again, it becomes a question of dead the program abend gracefully. In general, exceptions shouldn't happen except for well defined and expected cases. An access violation is still a bug, and the bug must be corrected. If for one don't trust an exception handler to try and 'fix' an access violation. Tim Smith Descartes Systems Sciences, Inc.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #10

          Out of memory exceptions are the biggest problem with this code. They are allocating it all over the place and never checking it. Since they rely so heavily on macros there is very little return code checking also. In a system that, as I said, is supposed to be 99.999% reliable, you must expect the unexpected and plan for an exception to occur. It is comical that the company is planning on spending thousands on redundant hardware, but doesn't see this type of coding to be of concern. If nothing else the experience has started my weekend with a much need laugh.

          T 1 Reply Last reply
          0
          • N Not Active

            Out of memory exceptions are the biggest problem with this code. They are allocating it all over the place and never checking it. Since they rely so heavily on macros there is very little return code checking also. In a system that, as I said, is supposed to be 99.999% reliable, you must expect the unexpected and plan for an exception to occur. It is comical that the company is planning on spending thousands on redundant hardware, but doesn't see this type of coding to be of concern. If nothing else the experience has started my weekend with a much need laugh.

            T Offline
            T Offline
            Tim Smith
            wrote on last edited by
            #11

            If nothing else the experience has started my weekend with a much need laugh. Heh, yeah. I have done that before. Sometimes with my own code. :eek: Tim Smith Descartes Systems Sciences, Inc.

            1 Reply Last reply
            0
            • T Tim Smith

              No exception handling Woohoo, at least he did one thing right. ;) Other than the fact that I can't use exception handling in WinCE, I find that most people don't have a clue how to properly use it. They just sort of throw it in because they think they should. Then don't really do anything with it. There are the cases where some moron decided that an exception was MUCH better than just returning a simple failure flag. Whine whine whine :) Tim Smith Descartes Systems Sciences, Inc.

              M Offline
              M Offline
              Marcus Spitzmiller
              wrote on last edited by
              #12

              Funny you should mention that. Altough I understand the concepts, I really have never been able to implement anything I was satisfied with. Do you know of any good reading material on some good exception handling techniques? Thanks, Marcus

              T W 2 Replies Last reply
              0
              • M Marcus Spitzmiller

                Funny you should mention that. Altough I understand the concepts, I really have never been able to implement anything I was satisfied with. Do you know of any good reading material on some good exception handling techniques? Thanks, Marcus

                T Offline
                T Offline
                Tim Smith
                wrote on last edited by
                #13

                Ack! No I don't. Even though I understand the theory behind exceptions, in practice I am of 'questionable' ability. Which probably colors my opinion on them. :) Tim Smith Descartes Systems Sciences, Inc.

                M 1 Reply Last reply
                0
                • T Tim Smith

                  Ack! No I don't. Even though I understand the theory behind exceptions, in practice I am of 'questionable' ability. Which probably colors my opinion on them. :) Tim Smith Descartes Systems Sciences, Inc.

                  M Offline
                  M Offline
                  Marcus Spitzmiller
                  wrote on last edited by
                  #14

                  Ditto....That's alright, exceptions are lame anyway. ;) Thanks, Marcus

                  C 1 Reply Last reply
                  0
                  • M Marcus Spitzmiller

                    Ditto....That's alright, exceptions are lame anyway. ;) Thanks, Marcus

                    C Offline
                    C Offline
                    ColinDavies
                    wrote on last edited by
                    #15

                    marcus78 wrote: Ditto....That's alright, exceptions are lame anyway. Ditto 2 Regardz Colin J Davies

                    Sonork ID 100.9197:Colin

                    I live in Bob's HungOut now

                    A good example of "Fully Managed" coding

                    1 Reply Last reply
                    0
                    • RaviBeeR RaviBee

                      It's really sad that there are so many people claiming to be software engineers, when all they engineer are poorly constructed designs and badly written code. Imho, unaware and undereducated managers shoulder a lot of the blame for this unhappy state of affairs. I think things will change only when the software development industry is held accountable like other industries such as makers of airplanes, toasters and water heaters. /ravi "There is always one more bug..." ravib@ravib.com http://www.ravib.com

                      N Offline
                      N Offline
                      Neville Franks
                      wrote on last edited by
                      #16

                      Ravi Bhavnani wrote: I think things will change only when the software development industry is held accountable like other industries such as makers of airplanes, toasters and water heaters. I agree with you but I really do have to wonder whether my toaster manufacture can be held accountable. About 6.53 times out of 10 the toast pops out so vigourously that it lands on the floor. Every time it happens I stand their jaw dropped wondering how in this day and age such a thing is possible.:confused: Neville Franks, Author of ED for Windows. www.getsoft.com

                      C RaviBeeR R 3 Replies Last reply
                      0
                      • N Neville Franks

                        Ravi Bhavnani wrote: I think things will change only when the software development industry is held accountable like other industries such as makers of airplanes, toasters and water heaters. I agree with you but I really do have to wonder whether my toaster manufacture can be held accountable. About 6.53 times out of 10 the toast pops out so vigourously that it lands on the floor. Every time it happens I stand their jaw dropped wondering how in this day and age such a thing is possible.:confused: Neville Franks, Author of ED for Windows. www.getsoft.com

                        C Offline
                        C Offline
                        Chris Maunder
                        wrote on last edited by
                        #17

                        Neville Franks wrote: About 6.53 times out of 10 the toast pops out so vigourously that it lands on the floor. Really? That's so cool. Can you get some MPEG footage of this? I'm more than happy to post it on CodeProject purely for the giggle factor. cheers, Chris Maunder

                        1 Reply Last reply
                        0
                        • N Not Active

                          I can't believe my eyes. I was looking over some code we were supposed to port for use in a W2K COM project. I found the previous authors had created about 800 lines of macros, divided into about 25+ header files (some with just one line). Their implementation was basically nothing more than calling these macros. No exception handling, code formatted with no regard to tabs, 30-40 blank lines in the middle of a routine. What gets even worse is the lead developer for this project thinks this is the best they can produce. Makes me glad to be a consultant. One, I'll always have work fixing their work, and two I can leave when the axe begins to fall.;P

                          G Offline
                          G Offline
                          George
                          wrote on last edited by
                          #18

                          I guess it's always the case that the other peoples code doesn't look the way we would expect it to. I am not sure about the macros and exceptions problem because it often depends on the problem and implementation and it might be justified. However the bad formatting of the code is quite bad. The 30-40 blank lines is really bad. If I was a manager and some of my people would produce blank lines like that I would simply fire the guy on the spot. People who do not take a second to review their code and leave mess behind are only to cause the troubles in the (near) future. People who review their code and think that's OK are not worthy to keep either. In my office the main problem I notice is a lot of copy-paste that leads to a huge multiplicated chunks of code that is a nightmare to maintain. I blame it for the company's policy to code fast and without proper design - that always forces people to take shortcuts to make job done fast.

                          1 Reply Last reply
                          0
                          • M Marcus Spitzmiller

                            Funny you should mention that. Altough I understand the concepts, I really have never been able to implement anything I was satisfied with. Do you know of any good reading material on some good exception handling techniques? Thanks, Marcus

                            W Offline
                            W Offline
                            Wilka
                            wrote on last edited by
                            #19

                            Do you know of any good reading material on some good exception handling techniques? Exceptional C++ - http://www.gotw.ca/publications/xc++.htm More Exceptional C++ - http://www.gotw.ca/publications/mxc++.htm - Wilka

                            1 Reply Last reply
                            0
                            • C Christian Graus

                              :eek: :eek: :eek: Until I started working on a debugging tool this week, I've written one macro ( mid, to return a value clamped between two values ). Macros are evil, in fact Stroustrup says they are usually indicative of bad design. He must have consulted there before you did. :-) Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

                              Sonork ID 100.10002:MeanManOz

                              I live in Bob's HungOut now

                              C Offline
                              C Offline
                              Chris Losinger
                              wrote on last edited by
                              #20

                              ****Christian Graus wrote: Macros are evil I disagree. I use them often in code where, if it weren't for speed considerations, i'd use a small subroutine. yes, i could use an inline function, but as i see it, aside from type checking (which isn't really required in the sections of code i'm talking about), inlines and macros are identical. ****Christian Graus wrote: Stroustrup says they are usually indicative of bad design that's quite a broad statement from someone who probably hasn't written every possible program under every possible constraint. :) -c


                              Smaller Animals Software, Inc.

                              C 1 Reply Last reply
                              0
                              • N Neville Franks

                                Ravi Bhavnani wrote: I think things will change only when the software development industry is held accountable like other industries such as makers of airplanes, toasters and water heaters. I agree with you but I really do have to wonder whether my toaster manufacture can be held accountable. About 6.53 times out of 10 the toast pops out so vigourously that it lands on the floor. Every time it happens I stand their jaw dropped wondering how in this day and age such a thing is possible.:confused: Neville Franks, Author of ED for Windows. www.getsoft.com

                                RaviBeeR Offline
                                RaviBeeR Offline
                                RaviBee
                                wrote on last edited by
                                #21

                                Neville, In the US, we have a non-profit watchdog organization (Consumer's Union) that publishes a monthly magazine (Consumer's Report) in which they review household kitchen appliances, among other things. The magazine accepts no advertising and has been partially responsible for exposing the truth about the Suzuki Samurai in the '80s. I think your errant toaster would make it to the magazine if you wrote to them and it was sold in the US. PS: Ed looks very cool! /ravi "There is always one more bug..." http://www.ravib.com ravib@ravib.com

                                1 Reply Last reply
                                0
                                • C Chris Losinger

                                  ****Christian Graus wrote: Macros are evil I disagree. I use them often in code where, if it weren't for speed considerations, i'd use a small subroutine. yes, i could use an inline function, but as i see it, aside from type checking (which isn't really required in the sections of code i'm talking about), inlines and macros are identical. ****Christian Graus wrote: Stroustrup says they are usually indicative of bad design that's quite a broad statement from someone who probably hasn't written every possible program under every possible constraint. :) -c


                                  Smaller Animals Software, Inc.

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

                                  Chris Losinger wrote: I use them often in code where, if it weren't for speed considerations, i'd use a small subroutine. Before yesterday I had a couple I used, I suspect in similar circumstances to you, when I need a small routine inside a loop iterating over an image's bits. I've had to write several over the past day, because of the nature of the code I am working on. I still believe they are an option to only use after careful consideration of available options. Chris Losinger wrote: that's quite a broad statement from someone who probably hasn't written every possible program under every possible constraint. I'm not sure why you're discounting the fact that he has had to consider the broadness of uses for C++ when he designed it. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

                                  Sonork ID 100.10002:MeanManOz

                                  I live in Bob's HungOut now

                                  C 1 Reply Last reply
                                  0
                                  • C Christian Graus

                                    Chris Losinger wrote: I use them often in code where, if it weren't for speed considerations, i'd use a small subroutine. Before yesterday I had a couple I used, I suspect in similar circumstances to you, when I need a small routine inside a loop iterating over an image's bits. I've had to write several over the past day, because of the nature of the code I am working on. I still believe they are an option to only use after careful consideration of available options. Chris Losinger wrote: that's quite a broad statement from someone who probably hasn't written every possible program under every possible constraint. I'm not sure why you're discounting the fact that he has had to consider the broadness of uses for C++ when he designed it. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

                                    Sonork ID 100.10002:MeanManOz

                                    I live in Bob's HungOut now

                                    C Offline
                                    C Offline
                                    Chris Losinger
                                    wrote on last edited by
                                    #23

                                    ****Christian Graus wrote: I'm not sure why you're discounting the fact that he has had to consider the broadness of uses for C++ when he designed it. because i discount most statements that are as broad as that one :). IMO, macros are no more dangerous than pointers, virtual functions, gotos or any other C++ concept. they are all perfectly valid and useful when used appropriately. -c


                                    Smaller Animals Software, Inc.

                                    C 1 Reply Last reply
                                    0
                                    • N Not Active

                                      I also find it hard to believe some of this code was written by someone with 10+ years experience and a Master's Degree. You can lead a horse to university, but you can't educate him. :)

                                      R Offline
                                      R Offline
                                      Roger Wright new
                                      wrote on last edited by
                                      #24

                                      When he got the degree, were the computers still made with vacuum tubes?

                                      1 Reply Last reply
                                      0
                                      • N Neville Franks

                                        Ravi Bhavnani wrote: I think things will change only when the software development industry is held accountable like other industries such as makers of airplanes, toasters and water heaters. I agree with you but I really do have to wonder whether my toaster manufacture can be held accountable. About 6.53 times out of 10 the toast pops out so vigourously that it lands on the floor. Every time it happens I stand their jaw dropped wondering how in this day and age such a thing is possible.:confused: Neville Franks, Author of ED for Windows. www.getsoft.com

                                        R Offline
                                        R Offline
                                        Roger Wright new
                                        wrote on last edited by
                                        #25

                                        Neville Franks wrote: About 6.53 times out of 10 the toast pops out so vigourously that it lands on the floor. I had one like that! After a time, I ceased thinking of its ballistic payload as toast and began viewing it as skeet for my BB gun. Great entertainment until a BB fell into the launcher, shorting the heating wires... Ah, sweet bedlam:-)

                                        1 Reply Last reply
                                        0
                                        • C Chris Losinger

                                          ****Christian Graus wrote: I'm not sure why you're discounting the fact that he has had to consider the broadness of uses for C++ when he designed it. because i discount most statements that are as broad as that one :). IMO, macros are no more dangerous than pointers, virtual functions, gotos or any other C++ concept. they are all perfectly valid and useful when used appropriately. -c


                                          Smaller Animals Software, Inc.

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

                                          Chris Losinger wrote: IMO, macros are no more dangerous than pointers, virtual functions, gotos or any other C++ concept. they are all perfectly valid and useful when used appropriately. That's probably true, pointers are obviously also dangerous if misused. But goto - that's just the Devil you're talking about. I use macros sparingly, pointers often, and goto not one in my entire time of using C++. Christian After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001

                                          Sonork ID 100.10002:MeanManOz

                                          I live in Bob's HungOut now

                                          C 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