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 are the worst programming habits?

What are the worst programming habits?

Scheduled Pinned Locked Moved The Lounge
helpquestion
152 Posts 69 Posters 7 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.
  • N Nish Nishant

    mark merrens wrote:

    People that tell you their code is 'self-commenting'.

    Sometimes, it is though.

    // check if user is valid
    if(IsUserValid(user))
    {
    // update the user
    UpdateUser(user);
    }
    else
    {
    // show a messagebox with an error
    MessageBox(error);
    }

    In that snippet, the comments are sorta annoying.

    Regards, Nish


    Latest article: Using the Microsoft Azure Storage Client Library for C++ Blog: voidnish.wordpress.com

    R Offline
    R Offline
    R Giskard Reventlov
    wrote on last edited by
    #9

    But mostly, when they feel the need to tell you it is, it isn't.

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. Those who seek perfection will only find imperfection nils illegitimus carborundum me, me, me me, in pictures

    1 Reply Last reply
    0
    • C Chris Maunder

      I was thinking about the things that bug me and came up with a short list

      1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
      2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
      3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
      4. Mystery side-effects in code.
      5. Magic numbers

      I'm guilty of 2 of these on occasion. What's your list?

      cheers Chris Maunder

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

      In order of how I have them listed below: 0) Use of VB. 1) Use of Convert and/or ToString rather than casting and/or Parsing. 2) Over-use of Reflection. Not caching and reusing information retrieved via Reflection. 3) Over-reliance on tools, especially third-party tools. 4) Monolithic classes, lack of modularity, non-single-responsibility. 5) Singletons. X| 6) Convoluted concatenation -- a String.Format will be clearer. 6.1) Concatenated SQL statements, when a parameterized statement is better on so many levels. 7) Not leveraging interfaces. 8) Not allowing polymorphism for no apparent reason. 9) Swallowing Exceptions. 10) Posting snippets of code that use uncommon, custon, or third-party classes and expecting everyone to know what they are.

      You'll never get very far if all you do is follow instructions.

      M L J M R 6 Replies Last reply
      0
      • C Chris Maunder

        I was thinking about the things that bug me and came up with a short list

        1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
        2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
        3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
        4. Mystery side-effects in code.
        5. Magic numbers

        I'm guilty of 2 of these on occasion. What's your list?

        cheers Chris Maunder

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

        If you need comments to explain what the code does, then the code is too complex. Formatting is a matter of taste, and there's a keyboard shortcut to automatically reformat in the VS-IDE. My worst programming habits;

        1. Removing the access modifier "private" from code, as it is redundant. Not a bad habit in my book, but apparently in everyone else's.
        2. Hitting F5 too regularly. Kills productivity if it takes 15 minutes to build.
        3. Reading CodeProject while building a solution. I cannot stare at the build-screen, especially since it does not provide adequate feedback on what it is doing. If it appears to be waiting for a long time then chances are that it gets killed using the task-manager.
        4. Coffee. With two suger, and two cups an hour, that adds to 32 lumps of suger.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        P D C 3 Replies Last reply
        0
        • P PIEBALDconsult

          In order of how I have them listed below: 0) Use of VB. 1) Use of Convert and/or ToString rather than casting and/or Parsing. 2) Over-use of Reflection. Not caching and reusing information retrieved via Reflection. 3) Over-reliance on tools, especially third-party tools. 4) Monolithic classes, lack of modularity, non-single-responsibility. 5) Singletons. X| 6) Convoluted concatenation -- a String.Format will be clearer. 6.1) Concatenated SQL statements, when a parameterized statement is better on so many levels. 7) Not leveraging interfaces. 8) Not allowing polymorphism for no apparent reason. 9) Swallowing Exceptions. 10) Posting snippets of code that use uncommon, custon, or third-party classes and expecting everyone to know what they are.

          You'll never get very far if all you do is follow instructions.

          M Offline
          M Offline
          Marco Bertschi
          wrote on last edited by
          #12

          PIEBALDconsult wrote:

          1. Singletons. X|

          I reckon valid use cases for singletons. Facade patterns, for example, especially in C++ code.

          PIEBALDconsult wrote:

          1. Use of Convert and/or ToString rather than casting and/or Parsing.

          I lost you there, can you please clarify?

          The console is a black place

          1 Reply Last reply
          0
          • C Chris Maunder

            I was thinking about the things that bug me and came up with a short list

            1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
            2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
            3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
            4. Mystery side-effects in code.
            5. Magic numbers

            I'm guilty of 2 of these on occasion. What's your list?

            cheers Chris Maunder

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

            - Wrong comments. Comments that pretend to explain the code, but the code and the explanation don't match. - Rambling comments. At least they're not wrong, but the useful part is hiding. - Unreachable code. Often mistaken for "defensive programming". Code that provably can't run is provably useless.

            H S 2 Replies Last reply
            0
            • P PIEBALDconsult

              In order of how I have them listed below: 0) Use of VB. 1) Use of Convert and/or ToString rather than casting and/or Parsing. 2) Over-use of Reflection. Not caching and reusing information retrieved via Reflection. 3) Over-reliance on tools, especially third-party tools. 4) Monolithic classes, lack of modularity, non-single-responsibility. 5) Singletons. X| 6) Convoluted concatenation -- a String.Format will be clearer. 6.1) Concatenated SQL statements, when a parameterized statement is better on so many levels. 7) Not leveraging interfaces. 8) Not allowing polymorphism for no apparent reason. 9) Swallowing Exceptions. 10) Posting snippets of code that use uncommon, custon, or third-party classes and expecting everyone to know what they are.

              You'll never get very far if all you do is follow instructions.

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

              PIEBALDconsult wrote:

              6.1) Concatenated SQL statements

              Revoke the programming license of anyone who does this.

              P 1 Reply Last reply
              0
              • C Chris Maunder

                I was thinking about the things that bug me and came up with a short list

                1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
                2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
                3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
                4. Mystery side-effects in code.
                5. Magic numbers

                I'm guilty of 2 of these on occasion. What's your list?

                cheers Chris Maunder

                J Offline
                J Offline
                jeron1
                wrote on last edited by
                #15

                All that you listed, especially the magic numbers. I would add "Not checking return values", assuming things are going to work is a recipe for pain. OT:

                Chris Maunder wrote:

                site down

                subconscious recollections of a nightmare? :)

                "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst

                1 Reply Last reply
                0
                • C Chris Maunder

                  I was thinking about the things that bug me and came up with a short list

                  1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
                  2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
                  3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
                  4. Mystery side-effects in code.
                  5. Magic numbers

                  I'm guilty of 2 of these on occasion. What's your list?

                  cheers Chris Maunder

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #16

                  I do #2, when I specifically have to work with an object Comments are my major bugbear: I enforce XML comments on all public methods (and add them to non-public ones) and have "warnings as errors" on, so I have to comment my methods as a bare minimum. The rest of the time, I reserve comments for where they are needed. 6) I hate comments that explain exactly what the code is telling you it is doing! I can read the code, dammit - I don't need you to put

                  if (customer.IsAnIdiot)
                  {
                  // If the customer is an idiot then we need to handle it.

                  1. Out of date comments. This gets my goat. Comments are there to help, when the code is complicated and more explanation is needed. So if you change the damn code, change the damn comments! Or you will hear the sound of a soft cough behind you, and it'll be me, with the ClueBat... 8) Variables names that don't reflect the use and / or purpose. Leaving control names at the VS default for example... ClueBat time!

                  Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  L B P 3 Replies Last reply
                  0
                  • C Chris Maunder

                    I was thinking about the things that bug me and came up with a short list

                    1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
                    2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
                    3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
                    4. Mystery side-effects in code.
                    5. Magic numbers

                    I'm guilty of 2 of these on occasion. What's your list?

                    cheers Chris Maunder

                    M Offline
                    M Offline
                    Maximilien
                    wrote on last edited by
                    #17

                    ctrl-c/ctrl-v

                    I'd rather be phishing!

                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      In order of how I have them listed below: 0) Use of VB. 1) Use of Convert and/or ToString rather than casting and/or Parsing. 2) Over-use of Reflection. Not caching and reusing information retrieved via Reflection. 3) Over-reliance on tools, especially third-party tools. 4) Monolithic classes, lack of modularity, non-single-responsibility. 5) Singletons. X| 6) Convoluted concatenation -- a String.Format will be clearer. 6.1) Concatenated SQL statements, when a parameterized statement is better on so many levels. 7) Not leveraging interfaces. 8) Not allowing polymorphism for no apparent reason. 9) Swallowing Exceptions. 10) Posting snippets of code that use uncommon, custon, or third-party classes and expecting everyone to know what they are.

                      You'll never get very far if all you do is follow instructions.

                      J Offline
                      J Offline
                      Jacquers
                      wrote on last edited by
                      #18

                      6.1 - I had to work on code today of a developer that left us last year. He used concatenated SQL statements... :| This is where something like Entity Framework comes in handy - let it handle your sql inserts / updates. There was also a whole lot of other bad coding habits. I blame the university where he studied though, seems like they didn't teach him good coding standards.

                      S 1 Reply Last reply
                      0
                      • C Chris Maunder

                        I was thinking about the things that bug me and came up with a short list

                        1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
                        2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
                        3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
                        4. Mystery side-effects in code.
                        5. Magic numbers

                        I'm guilty of 2 of these on occasion. What's your list?

                        cheers Chris Maunder

                        D Offline
                        D Offline
                        dan sh
                        wrote on last edited by
                        #19

                        I am currently working on something that has massive presence of #1, 2 and 4. Other than that I totally hate if someone mixes up naming conventions. I have my favorites but I am OK with any convention. Just stick to single bloody way. Other than that, for some reason, heavily parameterized methods and constructors to bother me. I also totally hate logic and calculations in constructors (unless that is really needed).

                        My CP workspace: Incredibly trivial and probably useless code samples[^]

                        1 Reply Last reply
                        0
                        • C Chris Maunder

                          I was thinking about the things that bug me and came up with a short list

                          1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
                          2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
                          3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
                          4. Mystery side-effects in code.
                          5. Magic numbers

                          I'm guilty of 2 of these on occasion. What's your list?

                          cheers Chris Maunder

                          J Offline
                          J Offline
                          JMK NI
                          wrote on last edited by
                          #20

                          Not sealing classes by default/crazy overuse of inheritance Just because something needs something else doesn't mean it is a base class of that other thing, I think in a modern programming language you rarely actually need to use inheritance Also, Code that does nothing, but hasn't been taken out of the project, eugh I rarely comment my code unless I am doing something weird, I assume the next developer will be at least as smart as me, if not much much smarter (likely) I might use o as a variable name if I'm maybe inside a for loop inside another for loop (using i for the outer one), everybody should know what for(var i = 0; i < blah; i++) means, anything more descriptive is a waste of keystrokes Everything else I agree with

                          D L 3 Replies Last reply
                          0
                          • L Lost User

                            If you need comments to explain what the code does, then the code is too complex. Formatting is a matter of taste, and there's a keyboard shortcut to automatically reformat in the VS-IDE. My worst programming habits;

                            1. Removing the access modifier "private" from code, as it is redundant. Not a bad habit in my book, but apparently in everyone else's.
                            2. Hitting F5 too regularly. Kills productivity if it takes 15 minutes to build.
                            3. Reading CodeProject while building a solution. I cannot stare at the build-screen, especially since it does not provide adequate feedback on what it is doing. If it appears to be waiting for a long time then chances are that it gets killed using the task-manager.
                            4. Coffee. With two suger, and two cups an hour, that adds to 32 lumps of suger.

                            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

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

                            Eddy Vluggen wrote:

                            Removing the access modifier "private" from code

                            There should be no default access modifiers; the developer's intent should be clearly specified. I don't want to have to guess, and you don't want me to keep asking you. Specify it, and decrease the hit to your own productivity caused by your juniors.

                            You'll never get very far if all you do is follow instructions.

                            L 1 Reply Last reply
                            0
                            • C Chris Maunder

                              I was thinking about the things that bug me and came up with a short list

                              1. No comments. I know - let's have a religious war etc, but I find no comments dangerous.
                              2. using o as a variable name. In fact using anything that's not sensible. ctx, dr_rfp_ptr, i2
                              3. Bad formatting. It's like walking into a house and being unable to sit down because of empty pizza boxes on the couch
                              4. Mystery side-effects in code.
                              5. Magic numbers

                              I'm guilty of 2 of these on occasion. What's your list?

                              cheers Chris Maunder

                              G Offline
                              G Offline
                              Gary Wheeler
                              wrote on last edited by
                              #22

                              Misspelled identifiers. Inconsistent naming for related items. C++ header files that group things by their access method (public:, protected:, private:) rather than putting related items together. Hungarian notation should die in a fire.

                              Software Zen: delete this;

                              P 1 Reply Last reply
                              0
                              • J JMK NI

                                Not sealing classes by default/crazy overuse of inheritance Just because something needs something else doesn't mean it is a base class of that other thing, I think in a modern programming language you rarely actually need to use inheritance Also, Code that does nothing, but hasn't been taken out of the project, eugh I rarely comment my code unless I am doing something weird, I assume the next developer will be at least as smart as me, if not much much smarter (likely) I might use o as a variable name if I'm maybe inside a for loop inside another for loop (using i for the outer one), everybody should know what for(var i = 0; i < blah; i++) means, anything more descriptive is a waste of keystrokes Everything else I agree with

                                D Offline
                                D Offline
                                dan sh
                                wrote on last edited by
                                #23

                                Use of var is justifiable? In my useless opinion, var is useless in .Net framework World.

                                My CP workspace: Incredibly trivial and probably useless code samples[^]

                                J OriginalGriffO 2 Replies Last reply
                                0
                                • L Lost User

                                  If you need comments to explain what the code does, then the code is too complex. Formatting is a matter of taste, and there's a keyboard shortcut to automatically reformat in the VS-IDE. My worst programming habits;

                                  1. Removing the access modifier "private" from code, as it is redundant. Not a bad habit in my book, but apparently in everyone else's.
                                  2. Hitting F5 too regularly. Kills productivity if it takes 15 minutes to build.
                                  3. Reading CodeProject while building a solution. I cannot stare at the build-screen, especially since it does not provide adequate feedback on what it is doing. If it appears to be waiting for a long time then chances are that it gets killed using the task-manager.
                                  4. Coffee. With two suger, and two cups an hour, that adds to 32 lumps of suger.

                                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                                  D Offline
                                  D Offline
                                  Dave Kreskowiak
                                  wrote on last edited by
                                  #24

                                  I gotta call foul on removing the private access specifier. In C# the default is private while in VB it's Public. I absolutely hate that and really dont want to have to remember what the defaults ars supposed to be when scanning over code for problems.

                                  A guide to posting questions on CodeProject

                                  How to debug small programs
                                  Dave Kreskowiak

                                  L 1 Reply Last reply
                                  0
                                  • J JMK NI

                                    Not sealing classes by default/crazy overuse of inheritance Just because something needs something else doesn't mean it is a base class of that other thing, I think in a modern programming language you rarely actually need to use inheritance Also, Code that does nothing, but hasn't been taken out of the project, eugh I rarely comment my code unless I am doing something weird, I assume the next developer will be at least as smart as me, if not much much smarter (likely) I might use o as a variable name if I'm maybe inside a for loop inside another for loop (using i for the outer one), everybody should know what for(var i = 0; i < blah; i++) means, anything more descriptive is a waste of keystrokes Everything else I agree with

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

                                    That var is obviously an int, and you didn't even save any characters there..

                                    J 1 Reply Last reply
                                    0
                                    • G Gary Wheeler

                                      Misspelled identifiers. Inconsistent naming for related items. C++ header files that group things by their access method (public:, protected:, private:) rather than putting related items together. Hungarian notation should die in a fire.

                                      Software Zen: delete this;

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

                                      Gary Wheeler wrote:

                                      Hungarian notation should die in a fire

                                      That's too good for it. However, have you read this: Making Wrong Code Look Wrong by Joel Spolsky[^]

                                      You'll never get very far if all you do is follow instructions.

                                      G S 2 Replies Last reply
                                      0
                                      • D dan sh

                                        Use of var is justifiable? In my useless opinion, var is useless in .Net framework World.

                                        My CP workspace: Incredibly trivial and probably useless code samples[^]

                                        J Offline
                                        J Offline
                                        JMK NI
                                        wrote on last edited by
                                        #27

                                        I disagree, in a situation like:

                                        CryptographicUnexpectedOperationException exception = new CryptographicUnexpectedOperationException();

                                        I find this more readable:

                                        var exception = new CryptographicUnexpectedOperationException();

                                        Typing CryptographicUnexpectedOperationException twice in such a short space I think is a bit redundant

                                        D F 2 Replies Last reply
                                        0
                                        • L Lost User

                                          That var is obviously an int, and you didn't even save any characters there..

                                          J Offline
                                          J Offline
                                          JMK NI
                                          wrote on last edited by
                                          #28

                                          I didn't waste any characters either :^)

                                          L 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