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. What is good code?

What is good code?

Scheduled Pinned Locked Moved The Lounge
questiondiscussion
104 Posts 39 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.
  • V V 0

    Slacker007 wrote:

    What is good code

    Code written by me and no one else, of course. You can have endless discussions, but IMHO good code is code that works (does the required job).

    V.

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

    V. wrote:

    good code is code that works

    I like where you are going with this. One of the reasons why I posted the question. I was up last night thinking about this after reading about someone who thinks they know what good code is.

    "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
    "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

    V A K 3 Replies Last reply
    0
    • S Slacker007

      Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?

      "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
      "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

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

      I would think that basically if it does what it was designed to do. Like an artist a masterpiece is in the eye of the beholder.

      VS2010/Atmel Studio 6.0 ToDo Manager Extension
      Version 3.0 now available.

      G 1 Reply Last reply
      0
      • S Slacker007

        Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?

        "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
        "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

        G Offline
        G Offline
        Gary R Wheeler
        wrote on last edited by
        #9

        Slacker007 wrote:

        Who determines if your code is good?

        First, I do. After 30 years in this business, I know when I've done a good job and when I haven't. Second, I work with a team of other developers on our product. They aren't shy when they find a bug in my stuff. Third, we have a test group. One of them is actually 'embedded' in our department full-time. 'Marcia the Test Terrier' is relentless. Fourth, field service. Our service guys are also not shy about bugs. They also have direct access to our two bug reporting systems (one is for development issues, the other for customer issues). Finally, customers. They've spent from $1.5M to $5M on our product. They have certain... expectations.

        Slacker007 wrote:

        What is good code and what are the precise criteria for giving it a status of "good"?

        Good code satisfies the customers' needs without undue cost. For the developers on my team, it means they don't have to jump through hoops to interface to my part of the product. For testers, they can perform meaningful, repeatable tests and easily report successes and failures. The service guys want the software to help them diagnose hardware problems (our product is a large printing press) and not get in their way. The customer wants the software to print, and wants to be able to have a lightly-trained monkey able to operate the machine. You can see that these 'customers' all have different needs, some of which conflict with each other.

        Slacker007 wrote:

        Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really?

        See my answer to your first question. There are lots of people to tell me when my code sucks. Relatively little positive feedback comes back. Occasionally Marcia the Test Terrier tells me she likes a new feature. The service guys will also come across with an 'about time you guys did this'. I only talk to customers directly on rare occasions, so I don't hear much from them. Objectively my code is somewhat old-fashioned. While I do tend to implement 'patterns' as defined by the Gang of Four, I'm not as formal about it. I've written code that used those patterns when the book authors were in diapers. Some of my code exhibits anti-pattern or 'code smells' that are presently deprecated. For example, I use underscores in names occasionally. It still works.

        Mike HankeyM E C 3 Replies Last reply
        0
        • Mike HankeyM Mike Hankey

          I would think that basically if it does what it was designed to do. Like an artist a masterpiece is in the eye of the beholder.

          VS2010/Atmel Studio 6.0 ToDo Manager Extension
          Version 3.0 now available.

          G Offline
          G Offline
          Gary R Wheeler
          wrote on last edited by
          #10

          Mike Hankey wrote:

          Like an artist a masterpiece is in the eye of the beholder

          My problem is that I feel like Michaelangelo when the Pope tells him "But I wanted the ceiling painted blue."

          Software Zen: delete this;

          Mike HankeyM 1 Reply Last reply
          0
          • G Gary R Wheeler

            Mike Hankey wrote:

            Like an artist a masterpiece is in the eye of the beholder

            My problem is that I feel like Michaelangelo when the Pope tells him "But I wanted the ceiling painted blue."

            Software Zen: delete this;

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

            Then it's time to convince the Pope that indeed the ceiling is blue it's just his perception and lack of glasses that make it otherwise.

            VS2010/Atmel Studio 6.0 ToDo Manager Extension
            Version 3.0 now available.

            1 Reply Last reply
            0
            • G Gary R Wheeler

              Slacker007 wrote:

              Who determines if your code is good?

              First, I do. After 30 years in this business, I know when I've done a good job and when I haven't. Second, I work with a team of other developers on our product. They aren't shy when they find a bug in my stuff. Third, we have a test group. One of them is actually 'embedded' in our department full-time. 'Marcia the Test Terrier' is relentless. Fourth, field service. Our service guys are also not shy about bugs. They also have direct access to our two bug reporting systems (one is for development issues, the other for customer issues). Finally, customers. They've spent from $1.5M to $5M on our product. They have certain... expectations.

              Slacker007 wrote:

              What is good code and what are the precise criteria for giving it a status of "good"?

              Good code satisfies the customers' needs without undue cost. For the developers on my team, it means they don't have to jump through hoops to interface to my part of the product. For testers, they can perform meaningful, repeatable tests and easily report successes and failures. The service guys want the software to help them diagnose hardware problems (our product is a large printing press) and not get in their way. The customer wants the software to print, and wants to be able to have a lightly-trained monkey able to operate the machine. You can see that these 'customers' all have different needs, some of which conflict with each other.

              Slacker007 wrote:

              Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really?

              See my answer to your first question. There are lots of people to tell me when my code sucks. Relatively little positive feedback comes back. Occasionally Marcia the Test Terrier tells me she likes a new feature. The service guys will also come across with an 'about time you guys did this'. I only talk to customers directly on rare occasions, so I don't hear much from them. Objectively my code is somewhat old-fashioned. While I do tend to implement 'patterns' as defined by the Gang of Four, I'm not as formal about it. I've written code that used those patterns when the book authors were in diapers. Some of my code exhibits anti-pattern or 'code smells' that are presently deprecated. For example, I use underscores in names occasionally. It still works.

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

              Excellent answer. Monet, Rembrandt? :)

              VS2010/Atmel Studio 6.0 ToDo Manager Extension
              Version 3.0 now available.

              G 1 Reply Last reply
              0
              • Mike HankeyM Mike Hankey

                Excellent answer. Monet, Rembrandt? :)

                VS2010/Atmel Studio 6.0 ToDo Manager Extension
                Version 3.0 now available.

                G Offline
                G Offline
                Gary R Wheeler
                wrote on last edited by
                #13

                The more Monet, the better.

                Software Zen: delete this;

                Mike HankeyM 1 Reply Last reply
                0
                • G Gary R Wheeler

                  The more Monet, the better.

                  Software Zen: delete this;

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

                  :laugh:

                  VS2010/Atmel Studio 6.0 ToDo Manager Extension
                  Version 3.0 now available.

                  1 Reply Last reply
                  0
                  • G Gary R Wheeler

                    Slacker007 wrote:

                    Who determines if your code is good?

                    First, I do. After 30 years in this business, I know when I've done a good job and when I haven't. Second, I work with a team of other developers on our product. They aren't shy when they find a bug in my stuff. Third, we have a test group. One of them is actually 'embedded' in our department full-time. 'Marcia the Test Terrier' is relentless. Fourth, field service. Our service guys are also not shy about bugs. They also have direct access to our two bug reporting systems (one is for development issues, the other for customer issues). Finally, customers. They've spent from $1.5M to $5M on our product. They have certain... expectations.

                    Slacker007 wrote:

                    What is good code and what are the precise criteria for giving it a status of "good"?

                    Good code satisfies the customers' needs without undue cost. For the developers on my team, it means they don't have to jump through hoops to interface to my part of the product. For testers, they can perform meaningful, repeatable tests and easily report successes and failures. The service guys want the software to help them diagnose hardware problems (our product is a large printing press) and not get in their way. The customer wants the software to print, and wants to be able to have a lightly-trained monkey able to operate the machine. You can see that these 'customers' all have different needs, some of which conflict with each other.

                    Slacker007 wrote:

                    Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really?

                    See my answer to your first question. There are lots of people to tell me when my code sucks. Relatively little positive feedback comes back. Occasionally Marcia the Test Terrier tells me she likes a new feature. The service guys will also come across with an 'about time you guys did this'. I only talk to customers directly on rare occasions, so I don't hear much from them. Objectively my code is somewhat old-fashioned. While I do tend to implement 'patterns' as defined by the Gang of Four, I'm not as formal about it. I've written code that used those patterns when the book authors were in diapers. Some of my code exhibits anti-pattern or 'code smells' that are presently deprecated. For example, I use underscores in names occasionally. It still works.

                    E Offline
                    E Offline
                    Espen Harlinn
                    wrote on last edited by
                    #15

                    Gary R. Wheeler wrote:

                    I've written code that used those patterns when the book authors were in diapers

                    Congratulations, you're keeping well. Both Erich and John Matthew was born in 61' and I guess Ralph and Richard were born at about the same time - give or take a few years. ;)

                    Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS My LinkedIn Profile

                    G 1 Reply Last reply
                    0
                    • S Slacker007

                      V. wrote:

                      good code is code that works

                      I like where you are going with this. One of the reasons why I posted the question. I was up last night thinking about this after reading about someone who thinks they know what good code is.

                      "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
                      "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

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

                      Slacker007 wrote:

                      someone who thinks they know what good code is

                      That's the key point. We all think we write good code. I can't imagine any professional programmer that would write bad code on purpose. There are people we use different naming conventions, different patterns or just plain old spaghetti code, but in the end, if the client is happy and the application works, it is not bad code. Could it be better? Probably and mostly, but in the end all these things are the programmers personal opinions. (eg. I can fix bugs in a matter of minutes in my own applications, but if you ask someone else to look at it, even if he knows the code very well, it will take longer, just because my mindset is different)

                      V.

                      C 1 Reply Last reply
                      0
                      • E Espen Harlinn

                        Gary R. Wheeler wrote:

                        I've written code that used those patterns when the book authors were in diapers

                        Congratulations, you're keeping well. Both Erich and John Matthew was born in 61' and I guess Ralph and Richard were born at about the same time - give or take a few years. ;)

                        Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS My LinkedIn Profile

                        G Offline
                        G Offline
                        Gary R Wheeler
                        wrote on last edited by
                        #17

                        Why worry about factual accuracy when you've got a perfectly good hyperbole going? :-D I was born in '61, BTW :doh:.

                        Software Zen: delete this;

                        E 1 Reply Last reply
                        0
                        • S Slacker007

                          Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?

                          "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
                          "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

                          R Offline
                          R Offline
                          realJSOP
                          wrote on last edited by
                          #18

                          If the code works as designed, it's good.

                          ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                          -----
                          You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                          -----
                          "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

                          S S E Z 4 Replies Last reply
                          0
                          • G Gary R Wheeler

                            Why worry about factual accuracy when you've got a perfectly good hyperbole going? :-D I was born in '61, BTW :doh:.

                            Software Zen: delete this;

                            E Offline
                            E Offline
                            Espen Harlinn
                            wrote on last edited by
                            #19

                            Gary R. Wheeler wrote:

                            Why worry about factual accuracy when you've got a perfectly good hyperbole going? :-D

                            It was kind of begging for a rejoinder though :laugh:

                            Gary R. Wheeler wrote:

                            I was born in '61, BTW :doh:.

                            Then you ARE really keeping well ;)

                            Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS My LinkedIn Profile

                            1 Reply Last reply
                            0
                            • R realJSOP

                              If the code works as designed, it's good.

                              ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                              -----
                              You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                              -----
                              "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

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

                              I agree.

                              "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
                              "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

                              H 1 Reply Last reply
                              0
                              • S Slacker007

                                I agree.

                                "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
                                "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

                                H Offline
                                H Offline
                                Henry Minute
                                wrote on last edited by
                                #21

                                Creep! :laugh:

                                Henry Minute Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus! When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is. Cogito ergo thumb - Sucking my thumb helps me to think.

                                1 Reply Last reply
                                0
                                • R realJSOP

                                  If the code works as designed, it's good.

                                  ".45 ACP - because shooting twice is just silly" - JSOP, 2010
                                  -----
                                  You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
                                  -----
                                  "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

                                  S Offline
                                  S Offline
                                  SSEAR
                                  wrote on last edited by
                                  #22

                                  public int Add(int num1, int num2)
                                  {
                                  return num1 + num2;
                                  }

                                  public int Add(int num1, int num2)
                                  {
                                  return num1 + num2 - 0;
                                  }

                                  Both code will work as it designed for. But which one is the best code?

                                  S C L 3 Replies Last reply
                                  0
                                  • S SSEAR

                                    public int Add(int num1, int num2)
                                    {
                                    return num1 + num2;
                                    }

                                    public int Add(int num1, int num2)
                                    {
                                    return num1 + num2 - 0;
                                    }

                                    Both code will work as it designed for. But which one is the best code?

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

                                    SSEAR wrote:

                                    Both code will work as it designed for. But which one is the best code?

                                    Ah! There in lies the question. If both work as designed, does it really matter, and whom does it matter too? ;)

                                    "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
                                    "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

                                    S 1 Reply Last reply
                                    0
                                    • S SSEAR

                                      public int Add(int num1, int num2)
                                      {
                                      return num1 + num2;
                                      }

                                      public int Add(int num1, int num2)
                                      {
                                      return num1 + num2 - 0;
                                      }

                                      Both code will work as it designed for. But which one is the best code?

                                      C Offline
                                      C Offline
                                      CPallini
                                      wrote on last edited by
                                      #24

                                      I like the second one: good for teaching the kids about the addition neutral element.

                                      Veni, vidi, vici.

                                      1 Reply Last reply
                                      0
                                      • S Slacker007

                                        Who determines if your code is good? What is good code and what are the precise criteria for giving it a status of "good"? Since most of your code will never be reviewed by your peers (outside of work) then how do you know it is worth a damn, really? If I think your code sucks but the next guy thinks it is good, then who is right? This kind of goes in line with my other thoughts about the "greatness" of an individual programmer. Who determines that a person is a great programmer and that person writes some damn good code? You? Me? None of the above? We obviously cannot make this determination about ourselves or our code. So who does?

                                        "the meat from that butcher is just the dogs danglies, absolutely amazing cuts of beef." - DaveAuld (2011)
                                        "No, that is just the earthly manifestation of the Great God Retardon." - Nagy Vilmos (2011) "It is the celestial scrotum of good luck!" - Nagy Vilmos (2011) "But you probably have the smoothest scrotum of any grown man" - Pete O'Hanlon (2012)

                                        E Offline
                                        E Offline
                                        Espen Harlinn
                                        wrote on last edited by
                                        #25

                                        Slacker007 wrote:

                                        What is good code and what are the precise criteria for giving it a status of "good"?

                                        There will never be any 'precise criteria' that will allow you to determine this.

                                        Slacker007 wrote:

                                        how do you know it is worth a damn, really?

                                        Does it work? if not, it's worthless ... Is it readable, consistent and does it conform to common conventions? If not it will be a nightmare to pick up in a couple of years. How much time have you spent debugging your code? I think this is a good indicator, the less time you spend in the debugger the better the quality of the code. Is the important stuff testable, and do you have a good suite of tests for that? I think 80% of the tests I've seen does little more than test that the developer is not schizofrenic. Writing good tests is at least as hard as writing the other stuff. I prefer quality over quantity. Is it easy to debug? Complex expressions are harder to debug. By splitting them up into multiple expressions your code will be easier to debug.

                                        Slacker007 wrote:

                                        So who does?

                                        Call in an external expert - preferably one who is well known for the quality of her/his work, and make it clear that you will not be offended when she/he has something less than favourable to say about your work. Done right this can be a great learning experience.

                                        Espen Harlinn Principal Architect, Software - Goodtech Projects & Services AS My LinkedIn Profile

                                        S 1 Reply Last reply
                                        0
                                        • V V 0

                                          Slacker007 wrote:

                                          someone who thinks they know what good code is

                                          That's the key point. We all think we write good code. I can't imagine any professional programmer that would write bad code on purpose. There are people we use different naming conventions, different patterns or just plain old spaghetti code, but in the end, if the client is happy and the application works, it is not bad code. Could it be better? Probably and mostly, but in the end all these things are the programmers personal opinions. (eg. I can fix bugs in a matter of minutes in my own applications, but if you ask someone else to look at it, even if he knows the code very well, it will take longer, just because my mindset is different)

                                          V.

                                          C Offline
                                          C Offline
                                          CPallini
                                          wrote on last edited by
                                          #26

                                          V. wrote:

                                          but in the end, if the client is happy and the application works, it is not bad code

                                          It may be ugly, though.

                                          Veni, vidi, vici.

                                          V L 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