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 makes code good?

What makes code good?

Scheduled Pinned Locked Moved The Lounge
wpfcsharpphpcomcollaboration
71 Posts 40 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.
  • A Abu Mami

    classic rock (loud) beer pizza

    D Offline
    D Offline
    Dulchase
    wrote on last edited by
    #62

    every code is good with enough beer :):)

    1 Reply Last reply
    0
    • J Josh Smith

      What do you think makes some code better than other code? I don't necessarily mean "good" in the sense that it is bug-free, that's a pipe dream. What are the most important things to you when working with code? I think the following attributes are always found in code I consider to be good: 1) Consistency - The coding styles, naming conventions, usage of patterns, etc. are adhered to throughout the codebase. If your team prefixes private fields with an underscore, all private fields should start with "_". 2) Thoughtful naming - The names of things should accurately convey their purpose. I find that some of the best programmers I know dwell on a method name, or class name, or field name for a long time if necessary. 3) Smart comments - Too many comments make it difficult to read the code, too few comments force you to read code which could easily be summarized in one sentence. I think that all non-private members of a type should be commented, all types should have a comment explaining their purpose, and any tricky/hacky/weird code should be verbosely commented. What about you?

      :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

      M Offline
      M Offline
      Mushtaque Nizamani
      wrote on last edited by
      #63

      * Good Layout * Avoiding Magic Numbers

      Best Regards, Mushq Mushtaque Ahmed Nizamani Software Engineer Ultimus Pakistan "English is my second language; please excuse any grammatical or spelling mistakes"

      1 Reply Last reply
      0
      • J Josh Smith

        What do you think makes some code better than other code? I don't necessarily mean "good" in the sense that it is bug-free, that's a pipe dream. What are the most important things to you when working with code? I think the following attributes are always found in code I consider to be good: 1) Consistency - The coding styles, naming conventions, usage of patterns, etc. are adhered to throughout the codebase. If your team prefixes private fields with an underscore, all private fields should start with "_". 2) Thoughtful naming - The names of things should accurately convey their purpose. I find that some of the best programmers I know dwell on a method name, or class name, or field name for a long time if necessary. 3) Smart comments - Too many comments make it difficult to read the code, too few comments force you to read code which could easily be summarized in one sentence. I think that all non-private members of a type should be commented, all types should have a comment explaining their purpose, and any tricky/hacky/weird code should be verbosely commented. What about you?

        :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

        A Offline
        A Offline
        AlexCode
        wrote on last edited by
        #64

        If we develop alone, this isn't quite a problem, we have our own naming conventions and such. When managing a team, even a small team, this represents a bigger problem to be solved. Each team member tend to develop their code on their own way, which end up with an application much like a code rhapsody. It's usually a good practice to document the project consistency guide-lines, not only for code but for the way of doing things like access a database, distribute business logic between assemblies and stored-procedures, etc. Alex

        1 Reply Last reply
        0
        • J Josh Smith

          Jim Crafton wrote:

          If I write it, it's good.

          You must have difficultly getting into buildings, considering that your ego is too big to fit through a door! ;P

          :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

          U Offline
          U Offline
          urbane tiger
          wrote on last edited by
          #65

          That's why they let him enter via the car park under the building:)

          1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            Currently, I am reading this book: Beautiful Code[^]. I must say that content wise it is one of the best books I have read. I will rank it high up with books: Code Complete, Design Patterns and Refactoring.

            Josh Smith wrote:

            Thoughtful naming

            Agreed! To me intent code should be just be obvious by reading it. If the code adheres to well known patterns things are a lot easier.

            Josh Smith wrote:

            I think that all non-private members of a type should be commented

            The tricky parts always should have comments. But I hate comment clutter. I personally hate XML comments (javadoc is a little better) and I wish if there was an alternative. When you publish an API all public members should be documented but I necessarily don't agree that they should have comments on top of them. For example, I hate comments likes these if they appear everywhere and just convey the obvious. However, for something not very obvious things have to be commented.

            public class Employee
            {
            ///
            /// Gets or sets the employee name
            ///
            public string Name
            {
            get {return this.name; }
            set { this.name = value; }
            }

            ///
            /// Call this method to increase the salary of the employee
            ///
            public void IncreaseSalary(double salary)
            {
            ....
            }

            }

            Another thing issue I have seen is sometimes you may use a well known design pattern and the meaning may not be obvious to some programmers but programmers who have read the design patterns book may immediately recognize the pattern and understand how the code works. In such a case I think I will prefer programmer education rather than cluttering the code.

            Co-Author ASP.NET AJAX in Action

            U Offline
            U Offline
            urbane tiger
            wrote on last edited by
            #66

            totally agree, the reason that I don't like the XML approach, is that it encourages this sort of thing, and we're all know who's the most guilty party in this respect. Re use of "patterns" all I would add is that if you're using a well known pattern then say so, either within the member names or in comments.

            1 Reply Last reply
            0
            • T ToddHileHoffer

              Damn, I must be a lousy programmer. 1)I never pay attention to consistency, becuase I always change my mind. Sometimes In my one page I don't even have the same prefix on the same type of object. 2)I never think much about a name because you can always rename somthing in Visual Studio (even if it does take a while for the program to update all the references) 3) I usually go back and add comments after I'm done just in case I have to update the app in the future. I doubt they are smart though. I always thought what made code good was 1:Efficiency - Meaning the code will scale for a lot of users (web based) and not hog resources (windows based) 2:Conciseness - Not writing 100 lines of code when you only need 10 3:Simplicity - No need to reinvent the wheel. I have seen some smart programmers write stuff that is really complicated just because they enjoy the challenge. 4: Good Class / Database Design - Most apps succede or fail based on the design of your database tables and or class objects.

              I didn't get any requirements for the signature

              U Offline
              U Offline
              urbane tiger
              wrote on last edited by
              #67

              re efficiency - not all software need be scaleable in the manner you suggest, eg I wouldn't want my pacemaker to run over the web, nor would I want it running Windows. re simplicity - depends on what one regards as complicated, I've known programmers who've never understood ternary operators or bitwise operations, yet I find such things usually add to code simplicity. re conciseness - I'd rather maintain 100 lines of code whose purpose is clear and easily understood, than 10 lines of obscure uncommented code. Concise code does not necessarily mean efficient code, a good optimising compiler often generates very efficient object code from what might look inefficient source, lets face it compiler writers are usually smarter than your average VB app programmer. That being said I do wonder whether the incremental compilers that many of use today have much in the way of optimization. I guess my message is good code should permit optimal compiler output. re design - agreed

              1 Reply Last reply
              0
              • J Josh Smith

                What do you think makes some code better than other code? I don't necessarily mean "good" in the sense that it is bug-free, that's a pipe dream. What are the most important things to you when working with code? I think the following attributes are always found in code I consider to be good: 1) Consistency - The coding styles, naming conventions, usage of patterns, etc. are adhered to throughout the codebase. If your team prefixes private fields with an underscore, all private fields should start with "_". 2) Thoughtful naming - The names of things should accurately convey their purpose. I find that some of the best programmers I know dwell on a method name, or class name, or field name for a long time if necessary. 3) Smart comments - Too many comments make it difficult to read the code, too few comments force you to read code which could easily be summarized in one sentence. I think that all non-private members of a type should be commented, all types should have a comment explaining their purpose, and any tricky/hacky/weird code should be verbosely commented. What about you?

                :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

                U Offline
                U Offline
                urbane tiger
                wrote on last edited by
                #68

                I may have missed it, but what about the code being directed at the right problem. How much code has been written, tested and documented only to find that that the solution it provides isn't what was wanted. No overloading of member names with information available from other sources - eg CustomerNameTextBoxApplicationFormReadOnly or cstnmTBXAppFormRO, not sure which is worse, probably the latter.

                1 Reply Last reply
                0
                • J Josh Smith

                  What do you think makes some code better than other code? I don't necessarily mean "good" in the sense that it is bug-free, that's a pipe dream. What are the most important things to you when working with code? I think the following attributes are always found in code I consider to be good: 1) Consistency - The coding styles, naming conventions, usage of patterns, etc. are adhered to throughout the codebase. If your team prefixes private fields with an underscore, all private fields should start with "_". 2) Thoughtful naming - The names of things should accurately convey their purpose. I find that some of the best programmers I know dwell on a method name, or class name, or field name for a long time if necessary. 3) Smart comments - Too many comments make it difficult to read the code, too few comments force you to read code which could easily be summarized in one sentence. I think that all non-private members of a type should be commented, all types should have a comment explaining their purpose, and any tricky/hacky/weird code should be verbosely commented. What about you?

                  :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

                  C Offline
                  C Offline
                  compiler
                  wrote on last edited by
                  #69

                  The only perfect code is code that isn't there. It's been said before, but it's worth repeating here. Simplify, simplify, simplify.

                  1 Reply Last reply
                  0
                  • J Josh Smith

                    What do you think makes some code better than other code? I don't necessarily mean "good" in the sense that it is bug-free, that's a pipe dream. What are the most important things to you when working with code? I think the following attributes are always found in code I consider to be good: 1) Consistency - The coding styles, naming conventions, usage of patterns, etc. are adhered to throughout the codebase. If your team prefixes private fields with an underscore, all private fields should start with "_". 2) Thoughtful naming - The names of things should accurately convey their purpose. I find that some of the best programmers I know dwell on a method name, or class name, or field name for a long time if necessary. 3) Smart comments - Too many comments make it difficult to read the code, too few comments force you to read code which could easily be summarized in one sentence. I think that all non-private members of a type should be commented, all types should have a comment explaining their purpose, and any tricky/hacky/weird code should be verbosely commented. What about you?

                    :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

                    O Offline
                    O Offline
                    Old Ed
                    wrote on last edited by
                    #70

                    Josh, I agree with your points and follow the same principles myself. However, in the 36-years I've worked as programmer I've come across some "ugly" code that in some cases was quite "good". Though my first reaction is usually "What the hell is this crap" when confronted with code that lacks comments and proper indentation, after slogging through the mess I've found clever solutions, functions, etc., that I wasn't previously aware of. Clean (design) and coding is clearly better, but some people are messy yet produce code that works. What are you gonna do? I've seen standards come and go and yet the bottom line is still the same. Edward...

                    1 Reply Last reply
                    0
                    • J Josh Smith

                      What do you think makes some code better than other code? I don't necessarily mean "good" in the sense that it is bug-free, that's a pipe dream. What are the most important things to you when working with code? I think the following attributes are always found in code I consider to be good: 1) Consistency - The coding styles, naming conventions, usage of patterns, etc. are adhered to throughout the codebase. If your team prefixes private fields with an underscore, all private fields should start with "_". 2) Thoughtful naming - The names of things should accurately convey their purpose. I find that some of the best programmers I know dwell on a method name, or class name, or field name for a long time if necessary. 3) Smart comments - Too many comments make it difficult to read the code, too few comments force you to read code which could easily be summarized in one sentence. I think that all non-private members of a type should be commented, all types should have a comment explaining their purpose, and any tricky/hacky/weird code should be verbosely commented. What about you?

                      :josh: My WPF Blog[^] Without a strive for perfection I would be terribly bored.

                      C Offline
                      C Offline
                      chabatflo
                      wrote on last edited by
                      #71

                      Programming with Delphi (3.0 to 7.0) as a professionnal since 11 years. 1) Consistency : I agree My procedure names always start by a noun, my function names by a verb. Function name returning a boolean always start by "Is..." 2) Thoughtful naming : Usually my variable, procedure, function names are quite long, but their naming reflects what they really are and Ctrl-C / Ctrl-V keystrokes are used very often. "Sometimes - The names of things should ..." No, not "Sometimes", "Always" ! 3) "any tricky/hacky/weird code should be verbosely commented." That's what I always quote specifically in my code when I think that in a few months I won't remember why I wrote code that way. CHABAT Florent FRANCE

                      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