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

                          F Offline
                          F Offline
                          Fran Porretto
                          wrote on last edited by
                          #102

                          Allow me to submit something a bit off-axis: a habit of thought.

                          In more than one place where I've worked, I've encountered persons so confident in their skills that they didn't bother to test "trivial changes." Such "trivial changes" caused major crashes in important products, more often than I (or they) would care to remember. Inasmuch as for many years it's been a large part of my responsibilities to train young software engineers, it's been the very first thing I've pounded on: there is no such thing as a change too small to test.

                          Some took the advice to heart, but not all -- and when the bills came due, the incredulity of the sinner at issue was often thick enough to slice: "But all I did was...!"

                          We're fallible, each and every one of us, from the dunces to the geniuses, and from the brand-new graduates to the fifty-year veterans. But an engineer's ego can be resistant to that homily...until he's experienced the consequences on his own hide.

                          My "favorite" case of excessive confidence involves a young turk -- let's call him Andy, as that was his name -- who was assigned a component in a large monolithic application intended to run on a VAX under VMS. Andy was excessively fond of assembly language, and was eager to write his piece in VAX assembler. I counseled him against it -- the rest of the application was written in C -- but couldn't dissuade him. To shorten the story a bit, some weeks later Andy presented me with his component, which I added to the build without comment. The resulting application ran for approximately twenty seconds before it crashed -- and it didn't just bring down the app; it crashed VMS with a "bug check" error.

                          The problem was, of course, in Andy's module. I pointed it out to him at once. The subsequent exchange ran roughly as follows:

                          FWP: Did you test it?
                          Andy: Well...
                          FWP: This instruction [I pointed it out] is out of sequence. You have to allocate and enable mapping registers before it will be valid.
                          Andy: Well...
                          FWP: I expected you to test this before you brought it to the link.
                          Andy: But it assembled without errors, so I figured it was right!

                          Words fail me, friends.

                          (This message is programming you in ways you cannot detect. Be afraid.)

                          G 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
                            loctrice
                            wrote on last edited by
                            #103

                            I'm all for comments when necessary. I know that is a wide range, but my pet peeve here touches on that range. I think comments can be useful, like if you need to remark on a pitfall about why the code is done that way. Or if you need specific thoughts to consider if you refactor. Stuff like that. However, when I encounter people who think code should be commented I run into two things that hit my peeve list: 1) comment everything, even if the comment is stupid 2) Don't worry about doing stupid things, because you can comment them. Use the comment instead of good architecture.

                            Elephant elephant elephant, sunshine sunshine sunshine

                            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
                              Spoon Of Doom
                              wrote on last edited by
                              #104

                              I've encountered a similar, but annoying variant of this. There were a whole bunch of functions in my old employer's code base which did nothing but call an almost identically named function, such as:

                              someFunc(int a, string b)
                              {
                              return some_Func(a, b);
                              }

                              In some cases, this went on for a step or two further, with some_Func calling some__Func (I HATE double underscores in code), which then again finally called the 'real' function someOtherFunc. I suppose it was the result of a messed up attempt at refactoring. It was hugely annoying when debugging.

                              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

                                A Offline
                                A Offline
                                Andres Cassagnes
                                wrote on last edited by
                                #105

                                I was working with a horrible C framework wich contains most of the worst programming habits. Very large functions (for about 4000 lines), no coments or coments like /*##@@&& and do something*/ (I swear its real) in a 1000 lines function and things like that. It was like the "1000 dont's about programming"

                                C, C++, Java, Verilog, VHDL, PHP, and still can´t speak english

                                1 Reply Last reply
                                0
                                • C Charl

                                  Team work often brings out the best (and the worst) in people. My peeves are about devs who indulge in: 1. Sending an email to the dev in the next cubicle instead of simply having a chat 2. Refusing to commit code until it is "perfect" 3. Making working code not work in the name of "refactoring" 4. Spending a week perfecting the latest LINQ statement and being unable to debug or optimise the thing 5. Deciding mid-project to change data access 6. Bitching about FXCop 7. Logging? What logging? 8. Hubris 9. Read the spec - real devs don't read specs! My two fav's are: Inline braces and swallowing exceptions

                                  P Offline
                                  P Offline
                                  Pete OHanlon
                                  wrote on last edited by
                                  #106

                                  Charl wrote:

                                  2. Refusing to commit code until it is "perfect"

                                  There's another side to this. Excessive check ins. You don't need to check in every single change every time you make the change - wait until you have a logical break and then check it in. I've seen people check in every 5 minutes, just checking in things like colour or border thickness changes. It wouldn't be so bad if the next checkin wasn't for the next colour.

                                  1 Reply Last reply
                                  0
                                  • R Roger Wright

                                    Since I don't do this for a living anymore, my opinion probably doesn't count for much. But back when I did do it, the cost of maintaining code far exceeded the cost of developing it, and I considered a lack of meaningful comments grounds for termination. I still do. Others in my list would include leaving commented-out code in production source, and embedding numeric constants in code for use in calculations. 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.

                                    Will Rogers never met me.

                                    J Offline
                                    J Offline
                                    J C Morris
                                    wrote on last edited by
                                    #107

                                    >back when I did do it, the cost of maintaining code far exceeded the >cost of developing it, and I considered a lack of meaningful comments >grounds for termination. I still do. +1 A friend of mine teaches programming for high-school students - and docks a student's grade if the programs aren't reasonably commented. Back in the early 1960s while in college I made some changes to a copy of Spacewar, and still have the source listings...but I have no idea today what those changes were. I hadn't learned about commenting (and in general neither had the other programmers who worked on the code). Now, as the senior engineer in my department at my POE I use those uncommented listings as examples of poor programming practice. (There are few things so horribly bad that they can't be used as a bad example.)

                                    1 Reply Last reply
                                    0
                                    • L Lost User

                                      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 Offline
                                      D Offline
                                      Dave Kreskowiak
                                      wrote on last edited by
                                      #108

                                      I like to be explicit in my code. There is no doubt in my intent. I just find it a bit strange that "private" is the only exception to access modifiers where you have to be explicit about everything but only because it's default. I'm just saying that the access modifier shouldn't have a default forcing you to be explicit in your intent and (granted hopefully) think about what you're doing. I am happy to say, as the other replier pointed out, that I'm not one of those that needs to be "saved from himself" because VB made everything Public by default and that's what generates tons and tons of bad "public everything" code. I don't believe that the problem is with VB. I believe the problem is with the education and the lax standards of what should be taught in school. I've has more than few degreed grads that couldn't tell me the difference between public and private. I've also heard most of those same grads say they've never written an API, to which I call BULLSHIT since every application contains it's own API, usually for the sole consumer being the application itself. I think the entire "private as default" or whatever modifier is default is a Band-Aid on a bigger problem. EDIT: And just for the record, I'm going to admit to being a hypocrite. I also rely on private being the default in my own code but, just because I do it, that in no way means I think it's a good idea.

                                      A guide to posting questions on CodeProject

                                      How to debug small programs
                                      Dave Kreskowiak

                                      P L 2 Replies 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

                                        D Offline
                                        D Offline
                                        Dan Neely
                                        wrote on last edited by
                                        #109

                                        Better auto complete systems don't need this. as a crutch to figure out what they should be offering as suggestions. It may have been useful a decade ago but belongs on the rubbish heap today.

                                        Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                                        1 Reply 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)

                                          D Offline
                                          D Offline
                                          Dan Neely
                                          wrote on last edited by
                                          #110

                                          To CYA in the future wrap that in a debug only block and let the app die more messily otherwise.

                                          Did you ever see history portrayed as an old man with a wise brow and pulseless heart, waging all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius Training a telescope on one’s own belly button will only reveal lint. You like that? You go right on staring at it. I prefer looking at galaxies. -- Sarah Hoyt

                                          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