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.
  • 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
    Plamen Dragiyski
    wrote on last edited by
    #73

    Since I use javascript I'm guilty about 2), but here it is: 6) use of lambda functions inside lambda functions (even inside lambda functions). 7) inline conditions, functions and constructing objects:

    var i, o;
    for(i = 0; (function() { ... })(); ++i) {
    o = new (objlist[i])();
    }

    Although I never allowed 3). If a tool cannot properly autoformat my code, according to my standards, then that tool is thrown away.

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

      S Offline
      S Offline
      Stefan_Lang
      wrote on last edited by
      #74

      That's got nothing to do with self-commenting code, it's just that the comments are pointless - which is yet another bad programming habit:

      n+1. comments that state the obvious
      

      In your example, comments could still be useful if they pointed out e. g. what is expected of the user object to be considered valid, what is expected of the user to fix the problem, or if the user not being valid may be an indication of an internal error, because the user object is expected to be in a valid state upon calling this function.

      GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

      1 Reply Last reply
      0
      • L Lost User

        Roger Wright wrote:

        I don't know if that last one is common anymore, but it used to drive me nuts, and I found it in a lot of code.

        Oh, it's still common! I found some code a while ago that the dev had obviously thought he'd done the right thing...

        const int FiveHundred= 500;

        Sure, re-factoring is easier (although it was only used in one place anyway) but not the most meaningfull names! (it was for a 1/2 second time out time)

        PooperPig - Coming Soon

        S Offline
        S Offline
        Stefan_Lang
        wrote on last edited by
        #75

        Could have been worse, like

        const int FiveHundred= 450;

        ;P

        GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

        S 1 Reply Last reply
        0
        • F Forogar

          7. Having two different methods that do exactly the same thing but with the arguments in a different order. I have come across this at at least three different places I have worked. Which one to delete when refactoring?

          - I would love to change the world, but they won’t give me the source code.

          S Offline
          S Offline
          Stefan_Lang
          wrote on last edited by
          #76

          Forogar wrote:

          Which one to delete when refactoring?

          Both. :cool:

          GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

          1 Reply Last reply
          0
          • J Jacquers

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

            Jacquers wrote:

            university [...] didn't teach him good coding standards

            Coding standards? At university? :omg:

            GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

            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

              R Offline
              R Offline
              R Erasmus
              wrote on last edited by
              #78

              Checking code into source control that doesn't compile.

              "Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>

              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

                R Offline
                R Offline
                R Erasmus
                wrote on last edited by
                #79

                Neglecting the design phase: - reverse engineering the design requirements because the design was neglected.

                "Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>

                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.

                  M Offline
                  M Offline
                  Martin Hart Turner
                  wrote on last edited by
                  #80
                  1. ;) 3) This can be a project killer, good observation. 4) There is no excuse nowadays, there are plenty of tools available to help with refactoring. 5) :mad: 6.1) Unforgivable! Good observations!
                  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
                    Peter Adam
                    wrote on last edited by
                    #81

                    2. Short variable names. But usually using my own conventions: Array processing: i for rows, j for columns, v for current value; read/written from/to file: d for data, c for counting, etc. Why? Because I try to keep 80 columns of code. C# constants are superfluous (MessageBoxDefaultButton.Button1 FTW!), no way to keep the 80 columns, so I use more descriptive variable names there.

                    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

                      S Offline
                      S Offline
                      Stefan Bogdan
                      wrote on last edited by
                      #82

                      Never ending methods.

                      1 Reply Last reply
                      0
                      • L Lost User

                        - 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 Offline
                        H Offline
                        Herbie Mountjoy
                        wrote on last edited by
                        #83

                        Re-using code blocks in different applications without checking that the pre-existing comments are relevant in the latest incarnation. I keep finding examples of this in my archive. Stupid boy...

                        I may not last forever but the mess I leave behind certainly will.

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

                          G Offline
                          G Offline
                          greldak
                          wrote on last edited by
                          #84

                          Nish Sivakumar wrote:

                          Sometimes, it is though.

                          not really - the comments that are there are irrelevant but the ones that are needed are missing. The user is valid so why does it need updating?

                          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

                            M Offline
                            M Offline
                            Member 9063556
                            wrote on last edited by
                            #85
                            1. Leaving Edits in the code (Edits are messages that often pop up in developmental purposes for our in-house testing) 2) Bad tabbing. Don't blame me, really. I use a different tabbing structure due to the program we use doesn't automatically tab things well.

                            if (Broken) then fix.this else !fix.this end-if

                            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

                              R Offline
                              R Offline
                              Rosenne
                              wrote on last edited by
                              #86

                              Wrong or obsolete comments.

                              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

                                M Offline
                                M Offline
                                Mel Padden
                                wrote on last edited by
                                #87

                                I've seen the best and worst of stuff, but I've grown so used to it I just edit it out. There are modern tools to autoformat code in any case, I think the only things I would seriously have a problem with on that list are 4 and 5. Worst coding pet peeve? Code that isn't written defensively, with a mind to robustness, or that is not fully tested.

                                I too dabbled in pacifism once.

                                1 Reply Last reply
                                0
                                • S Stefan_Lang

                                  Could have been worse, like

                                  const int FiveHundred= 450;

                                  ;P

                                  GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                                  S Offline
                                  S Offline
                                  SortaCore
                                  wrote on last edited by
                                  #88

                                  Some code I write includes the "sneaky minus".

                                  someFunc(300, 250 * abc, -(500-otherVar * (3+abc), 592.3f);
                                  // ^

                                  I generally document that, unless the logic shouldn't ever need changing.

                                  S 1 Reply Last reply
                                  0
                                  • P PIEBALDconsult

                                    Soooo... the class is private? :confused: How does that work? Even I avoid global:: -- by using an alias if necessary:

                                    using MySqlClient=global::MySql.Data.MySqlClient ;

                                    What the heck is a pfld_ ? A pointer to a fixed long double?

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

                                    S Offline
                                    S Offline
                                    SortaCore
                                    wrote on last edited by
                                    #89

                                    pfld_ is a pointer to a fixed long double and it ranks under other variables in testing. Hence, the underscore notation.

                                    1 Reply Last reply
                                    0
                                    • pkfoxP pkfox

                                      "this" was introduced for a reason and should be used.

                                      We can’t stop here, this is bat country - Hunter S Thompson RIP

                                      S Offline
                                      S Offline
                                      SortaCore
                                      wrote on last edited by
                                      #90

                                      class uhoh
                                      {
                                      bool yay;
                                      uhoh(bool yay)
                                      {
                                      this.yay = yay;
                                      }
                                      }

                                      ... is usually the only time I want to use "this". Unless there was another "uhoh" being involved in an uhoh function. Which is probably not good practice.

                                      1 Reply Last reply
                                      0
                                      • D Dave Kreskowiak

                                        What benefit? Saving 4 keystrokes?

                                        A guide to posting questions on CodeProject

                                        How to debug small programs
                                        Dave Kreskowiak

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

                                        I'm not into saving keystrokes; but it does convey the same information using less symbols. For your comparison:

                                        // Delphi style;
                                        procedure Test()
                                        begin
                                        end

                                        // C#
                                        void Test()
                                        {
                                        }

                                        Would you like to imply that we use "{" and "}" merely to save keystrokes? You cannot deny that C# is a bit more readable than COBOL. Still, feel free to state the obvious if you feel like you have to :) It's a non-discussion. Try

                                        11 + 2 = 13
                                        Eleven plus two is thirteen

                                        Would we prefer the first version, just to save keystrokes? And which of the two explains the fastest what is going on?

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

                                        D 1 Reply Last reply
                                        0
                                        • P PIEBALDconsult

                                          Soooo... the class is private? :confused: How does that work? Even I avoid global:: -- by using an alias if necessary:

                                          using MySqlClient=global::MySql.Data.MySqlClient ;

                                          What the heck is a pfld_ ? A pointer to a fixed long double?

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

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

                                          PIEBALDconsult wrote:

                                          the class is private? :confused: How does that work?

                                          Create a new console-application. Look at the access modifier for "Program" and it's entrypoint. Both are private. Surprised? :)

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

                                          P 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