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. Oh boy. I've given myself a challenge now.

Oh boy. I've given myself a challenge now.

Scheduled Pinned Locked Moved The Lounge
helptutoriallearningcomdebugging
32 Posts 21 Posters 0 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.
  • OriginalGriffO OriginalGriff

    I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

    "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 AntiTwitter: @DalekDave is now a follower!

    A Offline
    A Offline
    Amarnath S
    wrote on last edited by
    #5

    One more - Missing variable initialization

    1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

      "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 AntiTwitter: @DalekDave is now a follower!

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

      How about NullPointerException? That seems to be one that so many people do not even understand what it's about.

      1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

        "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 AntiTwitter: @DalekDave is now a follower!

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

        Two different variables, with much too similar names - and then using the wrong one. My_Increment My_Decrement

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

          "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 AntiTwitter: @DalekDave is now a follower!

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

          Something like this. Includes missing out on floor, ceiling and index and more. // Percentile calculator List values = new List { 1, 2, 3, 4, 5, 6 }; double percentileToFind = 0.90; // find 90% of 6 since there are 6 numbers int indexToLook = (int)Math.Round(values.Count * percentileToFind); double startingValue = values[indexToLook]; // Omitting rest of percentile calculation logic // 95th percentile percentileToFind = 0.95; // find 95% of 6 since there are 6 numbers indexToLook = (int)Math.Round(values.Count * percentileToFind); startingValue = values[indexToLook];

          "It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

          1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

            "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 AntiTwitter: @DalekDave is now a follower!

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

            Using the debugger is an admission of defeat. A option of last resort (just short of actually asking for help).

            1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

              "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 AntiTwitter: @DalekDave is now a follower!

              K Offline
              K Offline
              kmoorevs
              wrote on last edited by
              #10

              Division by 0, array index out of bounds, null values? :)

              "Go forth into the source" - Neal Morse "Hope is contagious"

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                "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 AntiTwitter: @DalekDave is now a follower!

                M Offline
                M Offline
                Matias Lopez
                wrote on last edited by
                #11

                var vAux = 'whatever...';
                if (vAux = null && vAux = undefined && vAux.length = 0)
                console.log('Error at ValidationCode!');

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                  "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 AntiTwitter: @DalekDave is now a follower!

                  M Offline
                  M Offline
                  Matthew Dennis
                  wrote on last edited by
                  #12

                  I think one point that is often missed in teaching coding is making sure you can show that your code is correct. Not necessarily TDD, but setting up some input that you know what the output should be. This is very helpful in understanding the problem, and helps you know when you are done.

                  "Time flies like an arrow. Fruit flies like a banana."

                  OriginalGriffO 1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                    "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 AntiTwitter: @DalekDave is now a follower!

                    D Offline
                    D Offline
                    DRHuff
                    wrote on last edited by
                    #13

                    Cut and paste errors x = x + 1; y = x + 1; (Slightly more complicated would be better) Because your brain sees what it wants. Not what is there! (My sons first comp sci program. He didn’t see it. I didn’t see it. but stepping through the debugger sure made it obvious!)

                    If you can't laugh at yourself - ask me and I will do it for you.

                    1 Reply Last reply
                    0
                    • M Matthew Dennis

                      I think one point that is often missed in teaching coding is making sure you can show that your code is correct. Not necessarily TDD, but setting up some input that you know what the output should be. This is very helpful in understanding the problem, and helps you know when you are done.

                      "Time flies like an arrow. Fruit flies like a banana."

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

                      I'd agree - and one of the planned articles is all about testing. I'll be mentioning it in "Debugging" but not to any depth.

                      "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 AntiTwitter: @DalekDave is now a follower!

                      "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
                      • OriginalGriffO OriginalGriff

                        I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                        "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 AntiTwitter: @DalekDave is now a follower!

                        K Offline
                        K Offline
                        k5054
                        wrote on last edited by
                        #15

                        Infinite or range-error loops e.g while(test = 1) or for(i = 100; i > 0; ++i) I know I'm guilty of both of these, on occasion.

                        Keep Calm and Carry On

                        K 1 Reply Last reply
                        0
                        • K k5054

                          Infinite or range-error loops e.g while(test = 1) or for(i = 100; i > 0; ++i) I know I'm guilty of both of these, on occasion.

                          Keep Calm and Carry On

                          K Offline
                          K Offline
                          kmoorevs
                          wrote on last edited by
                          #16

                          k5054 wrote:

                          Infinite

                          :thumbsup: and put a short counter on it so that it doesn't completely blow up! :laugh:

                          "Go forth into the source" - Neal Morse "Hope is contagious"

                          1 Reply Last reply
                          0
                          • OriginalGriffO OriginalGriff

                            I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                            "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 AntiTwitter: @DalekDave is now a follower!

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

                            We / I learned how to flowchart before learning to write code. Don't know how you get to one without the other (at some point), without a lot of "explaining".

                            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                            T 1 Reply Last reply
                            0
                            • L Lost User

                              We / I learned how to flowchart before learning to write code. Don't know how you get to one without the other (at some point), without a lot of "explaining".

                              "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                              T Offline
                              T Offline
                              trønderen
                              wrote on last edited by
                              #18

                              Comparing for equality two real valued calculated results, which should mathematically be identical, but due to limited precision, they differ in the least significant bit (or two). If you were working on old machines using 1-complement integer representation, you could also compare plus and minus zero for equality, but I haven't seen a 1-complement machine for quite a few years now. A related one: When casting (implied or explicitly) to a longer word length, will the upper bits be zero or sign bit filled? Note: This can be both language/datatype and machine architecture dependent. I once spent half a day to understand a single if(x>y) statement: Both alternative seemed to do exactly the same, just in slightly different order. The reason was an implied cast (from 8 to 16 bits - this was on an 8051) where "wrong" sign extension would wreck the result if the same order of execution was used in both cases. Edit: This was intended as a reply to the OP, not as a reply to Gerry.

                              1 Reply Last reply
                              0
                              • OriginalGriffO OriginalGriff

                                I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                                "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 AntiTwitter: @DalekDave is now a follower!

                                C Offline
                                C Offline
                                charles henington
                                wrote on last edited by
                                #19

                                Using iterative instead of declarative statements to manipulate collections using Linq??

                                M 1 Reply Last reply
                                0
                                • OriginalGriffO OriginalGriff

                                  I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                                  "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 AntiTwitter: @DalekDave is now a follower!

                                  M Offline
                                  M Offline
                                  Mycroft Holmes
                                  wrote on last edited by
                                  #20

                                  I'm not sure this can be done anymore, declare a global variable DateTime as an int. Worked in VB (possibly 6) and truly screwed up an application.

                                  Never underestimate the power of human stupidity - RAH I'm old. I know stuff - JSOP

                                  1 Reply Last reply
                                  0
                                  • OriginalGriffO OriginalGriff

                                    I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                                    "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 AntiTwitter: @DalekDave is now a follower!

                                    FreedMallocF Offline
                                    FreedMallocF Offline
                                    FreedMalloc
                                    wrote on last edited by
                                    #21

                                    I was once told to write a short snippet in C++ with a couple bugs in it. One obvious and one less obvious to give as a coding test to prospective new hires. It took me hours. Plus, I never docked a candidate that "failed" the test in an interview. And thus hold interview tests in the highest disdain. My suggestion: An if statement with 2 indented lines under the conditional but no enclosing code block delimiters (braces).

                                    if (x > y)
                                    x++;
                                    y++;

                                    1 Reply Last reply
                                    0
                                    • OriginalGriffO OriginalGriff

                                      I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                                      "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 AntiTwitter: @DalekDave is now a follower!

                                      E Offline
                                      E Offline
                                      englebart
                                      wrote on last edited by
                                      #22

                                      Integer arithmetic 3 / 2 Integer versus double If 3/2 == 1.5 Another post covers double == double. Always use code formatter to help with misleading indents/ missing braces.

                                      1 Reply Last reply
                                      0
                                      • C charles henington

                                        Using iterative instead of declarative statements to manipulate collections using Linq??

                                        M Offline
                                        M Offline
                                        Memtha
                                        wrote on last edited by
                                        #23

                                        >using Linq?? FTFY

                                        C 1 Reply Last reply
                                        0
                                        • OriginalGriffO OriginalGriff

                                          I'm working on a series of "How to Write Code to Solve a Problem, A Beginner's Guide" articles to cover the bits learners seem to have the most problems with*. So fare I've covered the "break the problem into smaller pieces" approach to getting started, and syntax errors. And the next one is a biggie: Debugging. And there is my problem. To show how to debug something I need to write some short-ish code with a small, subtle bug in it, prove it has a bug, and then show how to fix it. But ... have you ever tried to deliberately write code with a bug in? It's not as simple as I thought it would be ... In fact, I'm finding it a lot harder to write buggy code than I do to write good code! :laugh: * Other than being told "no, I won't do your homework for you" of course. Or maybe I should write one of those ... Hmmm.

                                          "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 AntiTwitter: @DalekDave is now a follower!

                                          M Offline
                                          M Offline
                                          Memtha
                                          wrote on last edited by
                                          #24

                                          I spent three months tracking down a bug in a 3d rendering system, burried under thousands of lines. Here's the gist of it. ``` struct vertex { double x, y, z; } struct model { struct vertex* vertices; size_t triangles;//every 3 verts = a triangle. If two triangles use the same vert, that vert is repeated. } void loadToGpu(struct model* m) { void* buffer = getDeviceBuffer(); memcpy(buffer, m->vertices, m->triangles*3); } ``` I hope at least a few of you have to look twice at this so I can feel a little better. ;)

                                          D 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