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.
  • 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
                • V V 0

                  S Houghtelin wrote:

                  we’ve been auditioning for a fourth member

                  Damn, too far away. sorry :-D

                  V.

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

                  I suppose travel for the weekly practice would get kind of expensive. :-D

                  It was broke, so I fixed it.

                  1 Reply Last reply
                  0
                  • E Espen Harlinn

                    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 Offline
                    C Offline
                    CPallini
                    wrote on last edited by
                    #57

                    Espen Harlinn wrote:

                    Basicly coding is design work, and can be seen as the last iteration of the whole design process.

                    Yes it can seen like that. Simply I don't see it like that.

                    Veni, vidi, vici.

                    E 1 Reply Last reply
                    0
                    • C CPallini

                      Espen Harlinn wrote:

                      Basicly coding is design work, and can be seen as the last iteration of the whole design process.

                      Yes it can seen like that. Simply I don't see it like that.

                      Veni, vidi, vici.

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

                      CPallini wrote:

                      Yes it can seen like that. Simply I don't see it like that.

                      Most people don't - personally I think it would be a good thing if they did.

                      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)

                        S Offline
                        S Offline
                        Single Step Debugger
                        wrote on last edited by
                        #59

                        Good code is a little code. If I see you’ve achieved the goal with minimum efforts in coding and maximum in thinking, for me you’re okay and I’ll be glad to work with you.

                        There is only one Vera Farmiga and Salma Hayek is her prophet! Advertise here – minimum three posts per day are guaranteed.

                        1 Reply Last reply
                        0
                        • C Chris Meech

                          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 Offline
                          G Offline
                          Gary R Wheeler
                          wrote on last edited by
                          #60

                          Thanks, Chris. After 30 years doing a job, and making and cleaning up a fair share of messes, you figure a few things out.

                          Software Zen: delete this;

                          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)

                            T Offline
                            T Offline
                            TheGreatAndPowerfulOz
                            wrote on last edited by
                            #61

                            Good code follows these 4 principles: 1. It works and gets the job done. 2. It is the least code that will do the job and no more. 3. It is efficient and performant. 4. It is easy to maintain and extend. These are all things that any programmer worth his salt can do for himself. If you can't ensure your code follows these simple principles then get a different profession.

                            If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
                            You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun

                            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)

                              A Offline
                              A Offline
                              AspDotNetDev
                              wrote on last edited by
                              #62

                              Some people seem to be confusing what good code is and what a good developer is. They're not the same thing. A good developer has no problem writing substandard code. If it's a prototype, they might consider writing substandard code. Good code may be written by a bad developer (or a good developer making a bad decision). The code could be a shining example of excellence, but if it took too long and wasted an employer's time, it was a bad decision to write it so well. If the code isn't in source control, that's a bad decision for good code. As far as good code goes, that can vary based on context, but even some of the rules for contextually good code can be generalized:

                              1. Code in the same style as the rest of the code base.
                              2. The above can have exceptions. If you have a new code file and the rest of the code base has crap style, code your file in a better style to set a good example.
                              3. Don't waste CPU cycles. Don't waste memory.
                              4. Waste CPU cycles and memory when it will make the code much more clear or faster to write.
                              5. Some code lives longer or is more widely used than other code. That code should have higher quality.
                              6. Avoid security vulnerabilities (e.g., SQL injection).
                              7. Code that makes use of other good code rather than reinventing the wheel is good code.
                              8. As a corollary, avoid copy/paste code.
                              9. Patterns are good, except when they're not. If the cost of the complexity is greater than the benefit it adds, it's not good.
                              10. Code should be written to adapt to likely change. If you think a feature will be added later, leave room for it to be added without making it a breaking change.

                              The list could go on and on and vary significantly depending on context.

                              Thou mewling ill-breeding pignut!

                              S 1 Reply Last reply
                              0
                              • Z ZurdoDev

                                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 Offline
                                R Offline
                                realJSOP
                                wrote on last edited by
                                #63

                                When you're on a tight schedule, if it was what it's supposed to do, it's "good" code. You guys are merely being pedantic, and are ignoring (or ignorant of) the realities of real-world development...

                                ".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 L Z 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)

                                  N Offline
                                  N Offline
                                  Nueman
                                  wrote on last edited by
                                  #64

                                  My users wear guns to work. I am still here. Therefore I write good code. Q.E.D ;P

                                  What me worry?

                                  1 Reply Last reply
                                  0
                                  • A AspDotNetDev

                                    Some people seem to be confusing what good code is and what a good developer is. They're not the same thing. A good developer has no problem writing substandard code. If it's a prototype, they might consider writing substandard code. Good code may be written by a bad developer (or a good developer making a bad decision). The code could be a shining example of excellence, but if it took too long and wasted an employer's time, it was a bad decision to write it so well. If the code isn't in source control, that's a bad decision for good code. As far as good code goes, that can vary based on context, but even some of the rules for contextually good code can be generalized:

                                    1. Code in the same style as the rest of the code base.
                                    2. The above can have exceptions. If you have a new code file and the rest of the code base has crap style, code your file in a better style to set a good example.
                                    3. Don't waste CPU cycles. Don't waste memory.
                                    4. Waste CPU cycles and memory when it will make the code much more clear or faster to write.
                                    5. Some code lives longer or is more widely used than other code. That code should have higher quality.
                                    6. Avoid security vulnerabilities (e.g., SQL injection).
                                    7. Code that makes use of other good code rather than reinventing the wheel is good code.
                                    8. As a corollary, avoid copy/paste code.
                                    9. Patterns are good, except when they're not. If the cost of the complexity is greater than the benefit it adds, it's not good.
                                    10. Code should be written to adapt to likely change. If you think a feature will be added later, leave room for it to be added without making it a breaking change.

                                    The list could go on and on and vary significantly depending on context.

                                    Thou mewling ill-breeding pignut!

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

                                    Your points are well made but I don't think you understood the point of my question. Some of the members who responded to my question, understood what I was trying to get to. Your list of 1-10 is what seems correct...for you. However, I don't agree with most of your list as criteria for good code. Does this mean I'm right? Of course not. Therein lies my point.

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

                                    A 1 Reply Last reply
                                    0
                                    • R realJSOP

                                      When you're on a tight schedule, if it was what it's supposed to do, it's "good" code. You guys are merely being pedantic, and are ignoring (or ignorant of) the realities of real-world development...

                                      ".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
                                      #66

                                      John Simmons / outlaw programmer wrote:

                                      When you're on a tight schedule, if it was what it's supposed to do, it's "good" code.
                                       
                                      You guys are merely being pedantic, and are ignoring (or ignorant of) the realities of real-world development...

                                      well said.

                                      "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 1 Reply Last reply
                                      0
                                      • S Slacker007

                                        Your points are well made but I don't think you understood the point of my question. Some of the members who responded to my question, understood what I was trying to get to. Your list of 1-10 is what seems correct...for you. However, I don't agree with most of your list as criteria for good code. Does this mean I'm right? Of course not. Therein lies my point.

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

                                        A Offline
                                        A Offline
                                        AspDotNetDev
                                        wrote on last edited by
                                        #67

                                        Your question and assertion seem to be based around the fact that good code is not knowable. This is much like the philosophical argument that right and wrong are subjective and any objective determination cannot be made. I largely agree with those concepts, however I also question the necessity of finding objective determinations of what is good/right/wrong/etc. Such an answer really only has relevance among sentient beings such as humans. The quality of code especially so (not too many platypodes care about the style of brackets you use). And code quality will be relevant to certain humans more than others. There are many dimensions to relevance you could use to judge code quality. For one, a customer probably cares most about how well the code functions (e.g., that it is bug free). However, customers can be pretty ignorant, so they may be unable to judge that code is future-proof, which saves them money (even if they are unaware of it). Then there is your boss. He might care most about getting things done in a timely manner. From his perspective, getting things done fast makes you a quality coder, but whether that means your code is good or not depends on the perspective. From your collegue who was educated with 3 PhD's, maybe your code doesn't look as pristine as she'd like. However, your practical nature might conclude that pristine code is a waste of time, or you might have a different idea of what pristine code looks like. Much like morality, judgement of good or bad depends on the perspective, and that perspective can vary depending on how you want to select a group. You may be right that there is no objective measure of good code. However, that does not mean that, say, the .Net community does not have a few guidelines. And I'd also add that the larger your group is from which you are considering a perspective, the more generic you can be in declaring rules for quality. There may be some absolutes from the widest perspective (all humans), but by that time they may be so generic as to be useless to you on a specific level. So I guess this is really a bigger discussion. One that probably wouldn't be resolved any sooner than the "right" philosophy is achieved. :)

                                        Thou mewling ill-breeding pignut!

                                        S 1 Reply Last reply
                                        0
                                        • R realJSOP

                                          When you're on a tight schedule, if it was what it's supposed to do, it's "good" code. You guys are merely being pedantic, and are ignoring (or ignorant of) the realities of real-world development...

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

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

                                          John Simmons / outlaw programmer wrote:

                                          ignoring (or ignorant of) the realities of real-world development

                                          I don't think so. In real world development, sure a schedule may be tight and it may be necessary to write code that is not 'as good as it could be' just to get it out the door, or to fix an urgent bug. But that still isn't good code, it is just working code. If it is left as-is, and the code base is modified over time, then such code can cause more and more issues (as you must know) If you're a good, experienced, programmer, then the likelihood of quickly developed code being poor is less, but we all know we sometimes cut corners to get the job done - and we all know it comes back to bite us (or our successor) in the bum when that happens. If someone writes hundreds of lines of spaghetti code to achieve what could have been written in a few lines of well structured code, by your measure, it is good code if the output is as required. But a part of the output should be the codes longevity and maintainability, not just the function return value.

                                          MVVM# - See how I did MVVM my way ___________________________________________ Man, you're a god. - walterhevedeich 26/05/2011 .\\axxx (That's an 'M')

                                          Z 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