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 32 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

    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
                        • 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

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

                          Can you explain the reason? :) There is no good argumentation. "This" is used for the nut-cases who don't want to prefix with an underscore, and it is one of the most abused keywords, littering code without adding ANY value whatsoever.

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

                          P 1 Reply Last reply
                          0
                          • L Lost User

                            PIEBALDconsult wrote:

                            the developer's intent should be clearly specified.

                            It IS clearly specified if it is omitted. It is not some arcane trick, it is not something that causes side-effects, and it improves readability. It is as usefull as typing "begin" and "end" instead of the default scope-blocks. It might take some getting used to, but it conveys the same amount of information using less symbols. That's kinda essential, and the reason why we are not programming in COBOL.

                            PIEBALDconsult wrote:

                            I don't want to have to guess

                            If you have to guess at the default access modifier in C#, you should not be writing in C#.

                            PIEBALDconsult wrote:

                            and decrease the hit to your own productivity caused by your juniors.

                            Should I prefix each class with a complete namespace? Otherwise they'd be guessing at which class it will take :D You explain a junior ONCE that everything that does not have a modifier is private. If they come asking, even once, then make them prefix everything. Using "this" and "that", using namespaces, using "global::". Throw in some hungarian systems, so they won't have to guess the type :suss:

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

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

                            Eddy Vluggen wrote:

                            Should I prefix each class with a complete namespace

                            Maybe not each, but I've found that some namespaces use way too simple names to be safe to use without! E. g. in C++ I never use using namespace std, since it clutters the global namespace with many symbols that are common enough that they may clash with just about every nontrivial application code.

                            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
                            • D Dave Kreskowiak

                              What benefit? Saving 4 keystrokes?

                              A guide to posting questions on CodeProject

                              How to debug small programs
                              Dave Kreskowiak

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

                              One of the common errors of OO design is making everything public. Being private by default means that this won't happen by accident, or out of sloppyness. i rather have the compiler complain that I forgot an accessor than having other programmers modify my internal state because I forgot to explicitely make them private!

                              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

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

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

                                harold aptroot wrote:

                                - Unreachable code. Often mistaken for "defensive programming". Code that provably can't run is provably useless.

                                Dunno about that one - I once inserted a check that I was 100% sure couldn't possibly fail, so I inserted a message saying this shouldn't be happening, and to please contact me. Thank god, it was a beta tester eventually seeing said message, not an actual user in production code - it turned out I was wrong on my 100% assumption... :-O

                                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)

                                L D 2 Replies Last reply
                                0
                                • S Stefan_Lang

                                  harold aptroot wrote:

                                  - Unreachable code. Often mistaken for "defensive programming". Code that provably can't run is provably useless.

                                  Dunno about that one - I once inserted a check that I was 100% sure couldn't possibly fail, so I inserted a message saying this shouldn't be happening, and to please contact me. Thank god, it was a beta tester eventually seeing said message, not an actual user in production code - it turned out I was wrong on my 100% assumption... :-O

                                  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)

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

                                  I hope it wasn't provably unreachable, that would have bad implications for the fabric of reality.

                                  P 1 Reply Last reply
                                  0
                                  • L Lost User

                                    PIEBALDconsult wrote:

                                    6.1) Concatenated SQL statements

                                    Revoke the programming license of anyone who does this.

                                    P Offline
                                    P Offline
                                    Peter Adam
                                    wrote on last edited by
                                    #98

                                    Then please show me the way parametrizing a table name, or field names in a query. Of course, you can keep hacking[^].

                                    P 1 Reply Last reply
                                    0
                                    • OriginalGriffO OriginalGriff

                                      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 – ∞)

                                      P Offline
                                      P Offline
                                      Peter Adam
                                      wrote on last edited by
                                      #99

                                      But if you are only scanning the code you can focus on the green lines instead of running an in-memory compiler :)

                                      1 Reply Last reply
                                      0
                                      • S SortaCore

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

                                        SortaCore wrote:

                                        unless the logic shouldn't ever need changing

                                        That's a rather roundabout way of saying 'always' ;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
                                        • S Stefan_Lang

                                          SortaCore wrote:

                                          unless the logic shouldn't ever need changing

                                          That's a rather roundabout way of saying 'always' ;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
                                          #101

                                          Yeah, when coordinates are no longer used in printing, the logic will need changing. :rolleyes:

                                          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