Stop the press, I made a bug!
-
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 -
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 HemingwayEnnis Ray Lynch, Jr. wrote:
Foo foo
Obviously, this is a marketing support application, right?
Software Zen:
delete this;
Fold With Us![^] -
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 HemingwayI 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
-
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
-
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)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
-
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 HemingwayEnnis 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
-
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
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. -
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.Ennis Ray Lynch, Jr. wrote:
To Make Marc ask questions.
hehe. :) Marc
-
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
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.
-
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.
Pete O'Hanlon wrote:
Because he's fubared beyond all belief.
Pretty much describes my life and my clients. :-D :rolleyes: Marc