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.
  • S Slacker007

    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 Offline
    S Offline
    SSEAR
    wrote on last edited by
    #36

    There are a number of aspects we should consider to judge a good code. Unfortunately these are really vague and relative to the situation

    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)

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

      Good code is fit for purpose. Of course the first idea of fit for purpose is that it fulfills the functional requirements and doesn't break the nonfunctional criteria. But as, or more, important might be maintainability. Commenting, clean object orientation and layering of library code might be more important than execution efficiency. Consider whether your project might live long, and might get maintained by several people, and whether those people will be with the project long enough to learn all its pitfalls or whether they will be temporary hires to fix up and add functionality. These factors affect how important documentation, naming conventions and avoiding optimizations that make the code hard to read. In the project I'm working on,good code is code that is tested, where the tests are marked up with requirements tracing so we can see who asked for the functionality and in what context. Then we can retire unwanted functionality which allows refactoring. Without that, we can't touch code in case we break something that some user relies on.

      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)

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #38

        I go the other way, I know when code is crappy. Mind you crappy code tends to appear whenever I look at old applications, the more you learn the better your code should be. If it does the job and I like the way it does the job then AFAIAC it is good code.

        Never underestimate the power of human stupidity RAH

        S 1 Reply Last reply
        0
        • E Espen Harlinn

          John Simmons / outlaw programmer wrote:

          If the code works as designed

          Have you seen code that doesn't work as designed?

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

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

          Espen Harlinn wrote:

          Have you seen code that doesn't work as designed?

          All the time.

          Veni, vidi, vici.

          E 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

            Z Offline
            Z Offline
            ZurdoDev
            wrote on last edited by
            #40

            Just because code works, does not mean it is good.

            There are only 10 types of people in the world, those who understand binary and those who don't.

            R 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)

              Z Offline
              Z Offline
              ZurdoDev
              wrote on last edited by
              #41

              Good code can be understood and modified by other developers. Good code is modular enough, but not too much, such that when change requests come it is usually not a major rewrite.

              There are only 10 types of people in the world, those who understand binary and those who don't.

              L 1 Reply Last reply
              0
              • M Mycroft Holmes

                I go the other way, I know when code is crappy. Mind you crappy code tends to appear whenever I look at old applications, the more you learn the better your code should be. If it does the job and I like the way it does the job then AFAIAC it is good code.

                Never underestimate the power of human stupidity RAH

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

                Mycroft Holmes wrote:

                whenever I look at old applications

                Exactly. Right now, someone says their code is good. 2 years later, it's crappy. You learn and you get better.

                "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)

                1 Reply Last reply
                0
                • C CPallini

                  Espen Harlinn wrote:

                  Have you seen code that doesn't work as designed?

                  All the time.

                  Veni, vidi, vici.

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

                  I think I'll have to modify this one to: Assuming that compilers, interpreters and hardware works as expected, have you ever seen code that doesn't work as designed? ( Think about what code really is ... )

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

                  C 1 Reply Last reply
                  0
                  • E Espen Harlinn

                    I think I'll have to modify this one to: Assuming that compilers, interpreters and hardware works as expected, have you ever seen code that doesn't work as designed? ( Think about what code really is ... )

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

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

                    To me 'design' is in a bit more abstract layer than 'develop'.

                    Veni, vidi, vici.

                    E 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.

                      C Offline
                      C Offline
                      Chris Meech
                      wrote on last edited by
                      #45

                      This so spot on. Good code is in part measured by how it is used. I don't often bookmark posts, but I did yours. It needs to be re-iterated every time someone asks again about code quality and how to determine it. :)

                      Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

                      G 1 Reply Last reply
                      0
                      • C CPallini

                        To me 'design' is in a bit more abstract layer than 'develop'.

                        Veni, vidi, vici.

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

                        Code is a design specification that can be translated into a program by a compiler or interpreted by a program - it's not a program.

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

                        C 1 Reply Last reply
                        0
                        • Z ZurdoDev

                          Good code can be understood and modified by other developers. Good code is modular enough, but not too much, such that when change requests come it is usually not a major rewrite.

                          There are only 10 types of people in the world, those who understand binary and those who don't.

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

                          ryanb31 wrote:

                          Good code can be understood and modified by other developers

                          Could you elaborate on which developers that should be? I mean, if part of the requirements is performance, then you can't make that true in general (some other developers will understand it, but not many). And code that doesn't meet the requirements is bad by definition..

                          1 Reply Last reply
                          0
                          • E Espen Harlinn

                            Code is a design specification that can be translated into a program by a compiler or interpreted by a program - it's not a program.

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

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

                            To me, between the design specification and the actual source code there is an implementation layer. I may have a clear design specification of the algorithm but development issues when trying to implement the algorithm itself into actual source code.

                            Veni, vidi, vici.

                            E 1 Reply Last reply
                            0
                            • E Espen Harlinn

                              S Houghtelin wrote:

                              I think the same holds true for a musical ensemble

                              A musical ensemble spends a lot of time practising, how many developers does that at all?

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

                              P Offline
                              P Offline
                              PIEBALDconsult
                              wrote on last edited by
                              #49

                              That's because musicians (and many others) have no UNDO.

                              S E 2 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)

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #50

                                Slacker007 wrote:

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

                                Peer review here at CP of course.

                                1 Reply Last reply
                                0
                                • C CPallini

                                  To me, between the design specification and the actual source code there is an implementation layer. I may have a clear design specification of the algorithm but development issues when trying to implement the algorithm itself into actual source code.

                                  Veni, vidi, vici.

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

                                  The original point was that code works as designed Basicly coding is design work, and can be seen as the last iteration of the whole design process.

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

                                  C 1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    That's because musicians (and many others) have no UNDO.

                                    S Offline
                                    S Offline
                                    S Houghtelin
                                    wrote on last edited by
                                    #52

                                    PIEBALDconsult wrote:

                                    That's because musicians (and many others) have no UNDO.

                                    I like that! :laugh: :laugh: :laugh: ...and musicians can't hide the mistakes by compiling.

                                    It was broke, so I fixed it.

                                    1 Reply Last reply
                                    0
                                    • P PIEBALDconsult

                                      That's because musicians (and many others) have no UNDO.

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

                                      Here is an example of programmers with no undo[^] - it performed as designed, but I'm fairly certain it did not perform as intended ...

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

                                      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
                                        Ennis Ray Lynch Jr
                                        wrote on last edited by
                                        #54

                                        All criteria must be met: 1) Meets statement of purpose 2) Easy for the uninitiated to read and bug fix 3) Easy to check out of SVN 4) Easy to refactor 5) Safe to make changes When I write code I aim to hit these points. Other more "senior" developers often snicker when I don't use an inline LINQ statement that spans several lines that connected to an automagic data source, that requires EF v (who cares) to be installed before it can be debugged. Instead, I like a couple of well intentioned class files and the .NET Framework. Sure, it may be more verbose but any idiot can debug it; and that is who will be replacing me.

                                        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

                                        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
                                          Ravi Bhavnani
                                          wrote on last edited by
                                          #55

                                          I identify "good" code as being code that:

                                          • works as intended
                                          • is easy to understand (and therefore debug)
                                          • is easy to extend

                                          /ravi

                                          My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

                                          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