Continue “What’s wrong with this code?”

I’d like an opinion on whether you are find the “what’s wrong with this code?” items useful at all, and whether you think I should continue to do them.

Also, if you have any ideas for how to make them better – ideas that wouldn’t take a lot of time – please let me know.

Comments (49)

  1. Anders Molin says:

    I like them, so please continue 🙂

  2. Josh Charles says:

    yes, please continue. I have found them to be very educational.

  3. karl says:

    Agreed, please continue

    Maybe you could provide the answer to the question in a hidden (click here to expand) div or something…

  4. I like them, however most of them are fairly basic. I’m not sure the level of developers that read your blog, but I would prefer if they were a little harder (or maybe more obscure).

  5. Sean Chase says:

    I’m always looking to learn something new. Keep em’ coming!

  6. I only syndicate your RSS feed because the first time I saw a "What’s wrong w/ this code?", it looked disturbingly and embarassingly like my own code.

    If it’s not too much trouble for you, then please continue.

  7. Steve Henke says:

    Yes, please. Good stuff.

  8. I really enjoy reading them. I know you are trying to keep the analysis open, but is there anyway you can hint at what specifically you are focusing on. It seems you have a code sample and half the comments are about the "style" of your code snippet.

    Give a little direction on what you are looking for. IOW, I know I am not checking the type before casting, but I trust the caller, so don’t this the type checking is what is wrong.

  9. Stephen Patten says:


  10. AndrewSeven says:

    Its good stuff, I like the answer/discussion posts.

    More obscure would be interesting too, stuff that passes the first test for code smell.

  11. Denny says:

    something I saw in some code that one guy did not "Get"

    needed an ID value on a disconnected PPC app.

    C# language

    used the time-count to give a number but cast it to "Int" the number is a uint64 and he cut it down to int and then folks wonderd why stange errors happend… it was like a random number F()!!


    1) the dev did not tell anyone he was casting as a narrowing conversion.

    2) it was used where money was at stake (orders taken on ppc dev)

    3) it was put in production w/o testing.

  12. Jens Cassel says:

    Of course!!! IMHO it’s very instructive!

  13. Luc Cluitmans says:

    Yes, please continue! Your and Larry Osterman’s "What’s wrong with this code" articles are always educational.

    As for ideas to make them better, sometimes the ‘answer’ depends on context information that you did not provide. I know it is hard to provide all required context, especially when you don’t want to give the answer away 🙂 Sometimes looking at an article (before posting it) with a viewpoint of "how can I misinterpret my own article" can be helpful…

  14. I like them. PLease don’t stop.

  15. Ken says:

    Yes, as it they provide a good list of pitfalls to watch out for.

    I’m interested in some examples with regards to virtual <-> overridden methods in a small class hierarchy. The trade of here is, that virtuals are slower, but overridden methods may lead to calling the wrong function when the object type-cast.

  16. Amit Bahree says:

    I think the discussions as quite good and as you pointed out in another post, one always ends up learning something or the other. What would be nice though is to create a seperate category for the post, e.g. then ppl can just syndicate that rss feed if they are interested in only "What wrong with this code" section.

  17. sam says:

    yes continue please. they are great.

  18. Paul Jackson says:

    Yes, please continue.

  19. Robert Burke says:

    Another ‘me too’ from a long-time follower. They’re great. Even if I don’t have time to think about them right away, I sometimes come back to them and enjoy the discussion.

  20. Vic Berggren says:

    Yeah man, continue. You could have an Eric Gunnersons What’s Wrong With This Code Blog. I’d tune into that daily.

    –>if you have any ideas

    Only as a suggestion… how about ‘themes’? This week Threading, next week IO, etc…

  21. "What’s wrong with this code?" is always useful and fun, especially coming from someone who knows so much about it and came from the devdiv team for C#.

  22. Bill says:

    Absolutely, I love them. I wouldn’t mind if they were a little bit tougher though.

  23. John Mollman says:

    Yes please, keep ’em coming! I like the "theme of the week" idea.

  24. C says:

    I find them valuable. You might provide a more explicit example in your answer of how to fix the problem. i.e. a ‘corrected’ code sample that matches the erronious one.

  25. Brad says:

    Please stop. Big waste of your time.




    Just kidding. I’m not even a C# programmer, or even a real windows developer, and I still like to read them. No way I’d ever be able to answer one, or understand half the comments, but they are still fun to read.

  26. One way to make them better is to discuss subtleties such as elegance of code, effective use of the language constructs/objects, naming conventions etc, not obvious things like "don’t call GC.Collect". Your audience is a smart crowd, let’s discuss more gentle things.

  27. Tim says:

    Please continue. One of them gave me a clue to a Interop problem a coworker was having, so they are worthwhile to me. I’d love seeing more Interop code.

  28. Sheeshers says:

    Yeah continue please. Newbies like me learn to write good .NET code by looking at how not to do it 🙂

  29. Louis S. Berman says:

    Definitely continue! My colleagues and I love to review them during lunch

  30. Doug says:

    I agree with all the above EXCEPT I’m a bit dubious about "Only as a suggestion… how about ‘themes’? This week Threading, next week IO, etc…" which I think might dampen the spontaneity / fun.

  31. I really enjoy reading through the questions and some of the posted answers. It’s a great way of keeping me in tip-top .net-shape.

  32. Sami says:

    This is a bit late,

    But please continue with them. They are really good.

  33. Anonymous Coward says:

    I really like them. I would recommend making them more technical though. I liked the GC.Collect() one.

    A lot of these are things where i’m able to show coworkers and be like "see! don’t do that!…it sucks!" (catching blind exceptions, calling GC).

    More difficult ones would be much appreciated though.

  34. Ollie Riches says:

    Keep’em coming….

  35. Lasse Vågsæther Karlsen says:

    I really like them, please continue.

    As for the "add answer as *click here to show answer*", that’s not the way to go. The point of these, I assume, is to make people think for a day or two. Obviously there’s something wrong with them otherwise you wouldn’t post them. If the problem doesn’t leap at you right away, a couple of days to churn over it is good.

    If you provide the answer right away, a lot of people will just read the problem, click the button, go "Oh, right, that makes sense", and go on back to coding having forgotten about the whole problem in the space of a few minutes.

  36. Mark Pearce says:

    +1 for continuing with this series. Little code samples are surprising useful for learning about big ideas.

  37. ee says:”>”>“>“>“>“>“>“>“>“>“>“>“>“>“>“>”>”>”>”>”>”>”>”>“>“>”>“>”>”>”>”>”>”>”>”>”>

  38. 前列腺炎 says:

    友情链接: [ 前列腺炎][ 前列腺炎][ 前列腺炎]