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

    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 Offline
    L Offline
    Lost User
    wrote on last edited by
    #39

    Dave Kreskowiak wrote:

    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.

    I hate that it's public in VB.NET too, but it does not change the way I look at C#. Having tried it, for several months, in both languages, to me, the benefit outweighs the possible disadvantage of confusion.

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

    D 1 Reply Last reply
    0
    • P PIEBALDconsult

      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 Offline
      G Offline
      Gary Wheeler
      wrote on last edited by
      #40

      Hmm. I agree with Joel but I stand by my dislike of the common Hungarian notation, despite Simonyi's original intent.

      Software Zen: delete this;

      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
        #41

        Comments like this: i=6; //set i to six :)

        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
          Simon_Whale
          wrote on last edited by
          #42

          My main bug bears are 1. Excessive whitespace between code lines 2. In code comment,for that complex method that are so short they are as useful as the var keyword.

          Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

          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

            C Offline
            C Offline
            Chris Losinger
            wrote on last edited by
            #43

            1. incorrect bracket placement 2. if (2 == var) 3. not enough whitespace 4. globals

            image processing toolkits | batch image processing

            1 Reply 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[^]

              C Offline
              C Offline
              Chris Losinger
              wrote on last edited by
              #44

              Eddy Vluggen wrote:

              there's a keyboard shortcut to automatically reformat in the VS-IDE.

              which is a total broken disaster in VS2013 (for C++ at least)

              image processing toolkits | batch image processing

              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
                David ONeil
                wrote on last edited by
                #45

                Currently dealing with a codebase that uses magic numbers and tucks them into the window's hMenu member (and uses them from there)! Ghhgh! The other nightmare offense in the code is using "m_" for: a) Some, but not all, member variables. b) Some, but not all, in function variables, including loop indexes. c) Some, but not all, passed function parameters. That was fun to get sorted - NOT. There were even a couple places where the same name was used in two or more different ways, so a project-wide replace would blow up. X| X| X| X| X|

                My website :: My book revealing the forgotten astronomy of our ancestors.

                1 Reply Last reply
                0
                • J JMK NI

                  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

                  F Offline
                  F Offline
                  Forogar
                  wrote on last edited by
                  #46

                  It's a pity that we can't use a condensed "new" format like:

                  CryptographicUnexpectedOperationException exception = new ();

                  which means the same as:

                  CryptographicUnexpectedOperationException exception = new CryptographicUnexpectedOperationException();

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

                  1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    var is handy in two places: 1) When using Linq and returning "An IEnumerable of something, gawddammit, but I have no idea what the compiler is going to call it" 2) To identify people whose code you can't trust because they have no idea or no interest in what type a variable should be. It may save five keystrokes to use var instead of IEnumerable<Customer> but it doesn't help understanding when you have to read the code later.

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

                    F Offline
                    F Offline
                    Forogar
                    wrote on last edited by
                    #47

                    I use var when I have some method to call that returns a humungously long-named type. I then immediately change it with the "Make Explicit" option. That way I don't have to type it out in full or select from a potentially huge list of intellisense suggestions.

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

                    OriginalGriffO 1 Reply Last reply
                    0
                    • F Forogar

                      I use var when I have some method to call that returns a humungously long-named type. I then immediately change it with the "Make Explicit" option. That way I don't have to type it out in full or select from a potentially huge list of intellisense suggestions.

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

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

                      Fine by me - it doesn't leave the var in the final code, or treat C# as if it was VB and "don't know, don't care" Dim

                      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

                      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
                        Jorgen Andersson
                        wrote on last edited by
                        #49

                        0. Systems hungarian.

                        Wrong is evil and must be defeated. - Jeff Ello[^]

                        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
                          Duncan Edwards Jones
                          wrote on last edited by
                          #50

                          -2. Swallowing an exception -1. Throwing an exception with no message and just the generic "Exception" class. 0. Using try-catch for normal program flow.. (And these are just the rules to the exception :-) )

                          1 Reply Last reply
                          0
                          • L Lost User

                            Adding oil to the fire, a practical example;

                            using System;
                            using System.Threading;
                            using System.Windows.Forms;
                            using System.Timers;

                            namespace ConsoleApplication5
                            {
                            class Program
                            {
                            Timer t = new System.Threading.Timer(null); // will not compile, as it is unclear which Timer
                            Timer t2 = new System.Windows.Forms.Timer(); // is declared (as opposed to the type instantiated)
                            Timer pfld_SysTimrTimrt3 = new System.Timers.Timer(); // using hungarian systems with namespace prefix

                                static void Main(global::System.String\[\]\[\] strSrgs)
                                {
                                    global::System.Console.ReadLine();
                                }
                            }
                            

                            }

                            And yes, the "console application template" has an entry point which is implicitly private.

                            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
                            #51

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

                              Sander RosselS Offline
                              Sander RosselS Offline
                              Sander Rossel
                              wrote on last edited by
                              #52

                              Things that bug me... 1. Comments. Too often have I seen comments that made no sense, were outdated, wrong or overly obvious. In fact I've learned to ignore comments as they've never helped me in any way. I guess programmers can't write English... 2. Code that is copy-pasted. Often the cause of bugs. 3. Swallowing exceptions. 4. Non-Object Oriented code in Object Oriented languages. 5. Formatting, you've said it. Bonus: 6. Not using brackets in if statements. Very dangerous... I'm working for a company that has worked with VB since the start. The first employees have worked with VB even longer and used Clipper before that. I've seen 1 through 5 all to often :sigh: I've come to hate 6 when we started doing C# and outsourced a project to another company. HORRIBLE!!! I read the code and didn't know if they meant it that way or if they had introduced subtle bugs... A lot of samples I get from the internet have it too. I probably forgot some stuff, but these are a few of my least-favourite things.

                              It's an OO world.

                              public class SanderRossel : Lazy<Person>
                              {
                              public void DoWork()
                              {
                              throw new NotSupportedException();
                              }
                              }

                              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
                                #53

                                I like to mark other's code with the unsafe keyword. That's what it is for, after all. Edit: Really bad things: - Stringly typing - Similar to magic numbers: Literal values and strings all over the place instead of enums, resources or similar. - Spaghetti code, or totally insanely structured code - Global variables, including abuse of the session or caches - managing data in dozens of separate variables instead of using even the most primitive kind of entity - not understanding the framework, being unwilling to learn and contaminating the code with flawed homebrew solutions

                                The language is JavaScript. that of Mordor, which I will not utter here
                                I hold an A-7 computer expert classification, Commodore. I'm well acquainted with Dr. Daystrom's theories and discoveries. The basic design of all our ship's computers are JavaScript.

                                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

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

                                  Ooh, good thread. Not ones I'm guilty of, but ones I call out in code reviews, that I haven't seen covered elsewhere in this thread: 0. Implementing code that's already part of the framework 1. Explicit path creation (rather than using Path.Combine) 2. Lines that are too long 3. Overly complex lines; these are normally ones that combine numerous statements together using ternary and coalescing null operators (it's a sure sign that someone has Resharper installed). 4. Talking about R#, converting clear code into a muddied part ordinary syntax, part LINQ abomination that you cannot remember what it does so you have to spend 20 minutes figuring out the damn thing. 5. Oh, and while we're at it with LINQ, myList.Where(p=> p.Id == aUniqueId).FirstOrDefault(); This one's a twofer - first of all, if it's a unique number, use SingleOrDefault not FirstOrDefault - you're only getting one value back. Secondly, learn how to use the power of LINQ, that Where statement is redundant so the statement can become myList.SingleOrDefault(p => p.Id == aUniqueId); 6. Not checking inputs into methods for validity. 7. When testing code, not asserting that something has happened. 8. Unnecessary try/catch blocks. 9. Blindly consuming exceptions - I'll have no On Error Resume Next behaviour please. 10. Not checking for null. I once saw a production system go boom because while the main code was properly checking nulls, the code that was reporting out that it couldn't do something because of null values didn't check the value out that it was attempting to log; thus blowing up the system. That's not all, but that should be enough to be getting on with.

                                  L 1 Reply Last reply
                                  0
                                  • L Lost User

                                    I like to mark other's code with the unsafe keyword. That's what it is for, after all. Edit: Really bad things: - Stringly typing - Similar to magic numbers: Literal values and strings all over the place instead of enums, resources or similar. - Spaghetti code, or totally insanely structured code - Global variables, including abuse of the session or caches - managing data in dozens of separate variables instead of using even the most primitive kind of entity - not understanding the framework, being unwilling to learn and contaminating the code with flawed homebrew solutions

                                    The language is JavaScript. that of Mordor, which I will not utter here
                                    I hold an A-7 computer expert classification, Commodore. I'm well acquainted with Dr. Daystrom's theories and discoveries. The basic design of all our ship's computers are JavaScript.

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

                                    CDP1802 wrote:

                                    mark other's code with the unsafe

                                    You might not be surprised to learn that I compile all my code with /unsafe. :cool:

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

                                    1 Reply Last reply
                                    0
                                    • L Lost User

                                      Dave Kreskowiak wrote:

                                      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.

                                      I hate that it's public in VB.NET too, but it does not change the way I look at C#. Having tried it, for several months, in both languages, to me, the benefit outweighs the possible disadvantage of confusion.

                                      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
                                      #56

                                      What benefit? Saving 4 keystrokes?

                                      A guide to posting questions on CodeProject

                                      How to debug small programs
                                      Dave Kreskowiak

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

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

                                        That isn't self-commenting code, it's badly commented code. Those comments are worthless - but that's not to say that some comments wouldn't be helpful

                                        PooperPig - Coming Soon

                                        K 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
                                          #58

                                          Willy nilly #including in large code bases. Then you get... Q) Why does my build take an hour? A) Because every source now indirectly includes every header

                                          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