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. Other Discussions
  3. Clever Code
  4. Stop the press, I made a bug!

Stop the press, I made a bug!

Scheduled Pinned Locked Moved Clever Code
helpcsharpcomquestioncode-review
10 Posts 7 Posters 11 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.
  • E Offline
    E Offline
    Ennis Ray Lynch Jr
    wrote on last edited by
    #1

    I love it when I make a mistake. It gives me the opportunity to be humble while being an arrogant A&& to others. Last week I made one, a fairly innocuous one that was very difficult to detect. Would it have been caught in a code review? YES! Yet I still can't get companies to use actual code reviews. Oh, the error? Why should I tell anyone? I had a section of code that used a significant amount of generic lists because order was specific and one list that was supposed to be a dictionary. Since I was looping through one list and using the "dictionary" from the key for a look-up it compiled and worked fine in dev but only blew up on prod test :(

    List<Foo> list = ...;
    List<Bar> bar = ...; //Should have been a dictionary guaranteed to have an entry for each SomeID
    foreach(Foo foo in list){
    foo.Bar = bar[foo.SomeId];
    }

    Need a C# Consultant? I'm available.
    Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

    G P M 3 Replies Last reply
    0
    • E Ennis Ray Lynch Jr

      I love it when I make a mistake. It gives me the opportunity to be humble while being an arrogant A&& to others. Last week I made one, a fairly innocuous one that was very difficult to detect. Would it have been caught in a code review? YES! Yet I still can't get companies to use actual code reviews. Oh, the error? Why should I tell anyone? I had a section of code that used a significant amount of generic lists because order was specific and one list that was supposed to be a dictionary. Since I was looping through one list and using the "dictionary" from the key for a look-up it compiled and worked fine in dev but only blew up on prod test :(

      List<Foo> list = ...;
      List<Bar> bar = ...; //Should have been a dictionary guaranteed to have an entry for each SomeID
      foreach(Foo foo in list){
      foo.Bar = bar[foo.SomeId];
      }

      Need a C# Consultant? I'm available.
      Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      Ennis Ray Lynch, Jr. wrote:

      Foo foo

      Obviously, this is a marketing support application, right?

      Software Zen: delete this;
      Fold With Us![^]

      1 Reply Last reply
      0
      • E Ennis Ray Lynch Jr

        I love it when I make a mistake. It gives me the opportunity to be humble while being an arrogant A&& to others. Last week I made one, a fairly innocuous one that was very difficult to detect. Would it have been caught in a code review? YES! Yet I still can't get companies to use actual code reviews. Oh, the error? Why should I tell anyone? I had a section of code that used a significant amount of generic lists because order was specific and one list that was supposed to be a dictionary. Since I was looping through one list and using the "dictionary" from the key for a look-up it compiled and worked fine in dev but only blew up on prod test :(

        List<Foo> list = ...;
        List<Bar> bar = ...; //Should have been a dictionary guaranteed to have an entry for each SomeID
        foreach(Foo foo in list){
        foo.Bar = bar[foo.SomeId];
        }

        Need a C# Consultant? I'm available.
        Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

        P Offline
        P Offline
        Paul Sanders the other one
        wrote on last edited by
        #3

        I have no idea what you are on about and I don't believe in code reviews. Presumably you are changing the list as you work your way through it, but I'm not sure and I think it unrealistic to expect someone else who probably has a lot of other things to do to pick up a subtle programming mistake of this nature purely by inspecting the code. What I do believe in is what I think of as white-box testing. The way I do this is to use the debugger to force the code through all possible code paths, at least once. Error handling is a particularly good example of this - it rarely gets tested at all otherwise. 'Set Next Statement' and Edit 'n Continue are wonderful tools for this kind of work, you can get a lot done in a short time and it really helps you build confidence in your code. Probably wouldn't have helped with your particular example, but I thought I would share anyway. Also: pepper your code with asserts, leave them in your production code and make it easy for users (or testers) to report them to you. All code contains bugs, and the trick of pinning them down in a live app is to catch them as close to the root of the problem as possible. In your case, assert (key in dictionary) would be a good candidate There, now who is the arrogant A&&? Well, me of course. Sometimes I just can't help myself :) Happy coding.

        Paul Sanders http://www.alpinesoft.co.uk

        L 1 Reply Last reply
        0
        • P Paul Sanders the other one

          I have no idea what you are on about and I don't believe in code reviews. Presumably you are changing the list as you work your way through it, but I'm not sure and I think it unrealistic to expect someone else who probably has a lot of other things to do to pick up a subtle programming mistake of this nature purely by inspecting the code. What I do believe in is what I think of as white-box testing. The way I do this is to use the debugger to force the code through all possible code paths, at least once. Error handling is a particularly good example of this - it rarely gets tested at all otherwise. 'Set Next Statement' and Edit 'n Continue are wonderful tools for this kind of work, you can get a lot done in a short time and it really helps you build confidence in your code. Probably wouldn't have helped with your particular example, but I thought I would share anyway. Also: pepper your code with asserts, leave them in your production code and make it easy for users (or testers) to report them to you. All code contains bugs, and the trick of pinning them down in a live app is to catch them as close to the root of the problem as possible. In your case, assert (key in dictionary) would be a good candidate There, now who is the arrogant A&&? Well, me of course. Sometimes I just can't help myself :) Happy coding.

          Paul Sanders http://www.alpinesoft.co.uk

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          I cant spot it either from the sample he gave...

          xacc.ide - now with TabsToSpaces support
          IronScheme - 1.0 alpha 4a out now (29 May 2008)

          P 1 Reply Last reply
          0
          • L leppie

            I cant spot it either from the sample he gave...

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #5

            Same here. I don't really see it, unless really missing something here. :rolleyes:

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

            1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              I love it when I make a mistake. It gives me the opportunity to be humble while being an arrogant A&& to others. Last week I made one, a fairly innocuous one that was very difficult to detect. Would it have been caught in a code review? YES! Yet I still can't get companies to use actual code reviews. Oh, the error? Why should I tell anyone? I had a section of code that used a significant amount of generic lists because order was specific and one list that was supposed to be a dictionary. Since I was looping through one list and using the "dictionary" from the key for a look-up it compiled and worked fine in dev but only blew up on prod test :(

              List<Foo> list = ...;
              List<Bar> bar = ...; //Should have been a dictionary guaranteed to have an entry for each SomeID
              foreach(Foo foo in list){
              foo.Bar = bar[foo.SomeId];
              }

              Need a C# Consultant? I'm available.
              Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway

              M Offline
              M Offline
              Marc Clifton
              wrote on last edited by
              #6

              Ennis Ray Lynch, Jr. wrote:

              foo.Bar = bar[foo.SomeId];

              foo.SomeId is of type Bar? WTF? If you already have Bar, why are you assigning it to foo.Bar? Marc

              Thyme In The Country Interacx My Blog

              E P 2 Replies Last reply
              0
              • M Marc Clifton

                Ennis Ray Lynch, Jr. wrote:

                foo.Bar = bar[foo.SomeId];

                foo.SomeId is of type Bar? WTF? If you already have Bar, why are you assigning it to foo.Bar? Marc

                Thyme In The Country Interacx My Blog

                E Offline
                E Offline
                Ennis Ray Lynch Jr
                wrote on last edited by
                #7

                To Make Marc ask questions.

                Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
                Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
                Most of this sig is for Google, not ego.

                M 1 Reply Last reply
                0
                • E Ennis Ray Lynch Jr

                  To Make Marc ask questions.

                  Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
                  Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
                  Most of this sig is for Google, not ego.

                  M Offline
                  M Offline
                  Marc Clifton
                  wrote on last edited by
                  #8

                  Ennis Ray Lynch, Jr. wrote:

                  To Make Marc ask questions.

                  hehe. :) Marc

                  Thyme In The Country Interacx My Blog

                  1 Reply Last reply
                  0
                  • M Marc Clifton

                    Ennis Ray Lynch, Jr. wrote:

                    foo.Bar = bar[foo.SomeId];

                    foo.SomeId is of type Bar? WTF? If you already have Bar, why are you assigning it to foo.Bar? Marc

                    Thyme In The Country Interacx My Blog

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

                    Marc Clifton wrote:

                    why are you assigning it to foo.Bar

                    Because he's fubared beyond all belief. ;)

                    Deja View - the feeling that you've seen this post before.

                    My blog | My articles

                    M 1 Reply Last reply
                    0
                    • P Pete OHanlon

                      Marc Clifton wrote:

                      why are you assigning it to foo.Bar

                      Because he's fubared beyond all belief. ;)

                      Deja View - the feeling that you've seen this post before.

                      My blog | My articles

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #10

                      Pete O'Hanlon wrote:

                      Because he's fubared beyond all belief.

                      Pretty much describes my life and my clients. :-D :rolleyes: Marc

                      Thyme In The Country Interacx My Blog

                      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