I know this has been well covered by others, but I needed this for my book, so here it is:

I know this has been well covered by others, but I needed this for my book, so here it is:

http://www.nickhodges.com/post/Enumerating-and-the-for%E2%80%A6in-Loop.aspx
http://www.nickhodges.com/post/Enumerating-and-the-for%E2%80%A6in-Loop.aspx

Comments

  1. It looks like adding comment on your blog doesn't work. When I click "Save comment", it runs forever saying "Saving the comment..."

    ReplyDelete
  2. Well, the comment feature works with Chrome but doesn't work with IE9.

    ReplyDelete
  3. I would be actually ary of making everything enumerable, as it makes everything look like a nail to a convenient for-in hammer.
    Enumeration is only good when order is not important, you're not mutation the collection (adding/removing), and bugs/errors aren't expected (since you don't have index nor path information about the object you're processing).
    For anything more complex cursors are preferable (enumerators are the simplest form of cursors)

    ReplyDelete
  4. Eric Grange But if you got a cursor it's nice to have an enumerable wrapper for when you just want to read/modify each element.

    ReplyDelete
  5. Asbjørn Heid If you have a cursor you should probably always avoid the enumerable, as the cursor is debuggable easily, while the enumerable for-in loop isn't (not without dropping down to cpu view...)

    ReplyDelete
  6. Eric Grange Not sure I understand, when debugging you could always trap the MoveNext, GetCurrent etc calls, if really needed. I must admit I haven't found a need once the wrapper is completed though. Though my wrappers are simple, so perhaps that's it :)

    ReplyDelete
  7. Asbjørn Heid This isn't for bugged enumerators, but when you have something that fails in whatever the loop is doing, and you want to know what object is failing (knowing it by its index, it position in the list, etc.) so you can diagnose directly when the exception occurs (rather than having to step through, place conditional breakpoints, etc.)

    ReplyDelete
  8. Eric Grange Ok fair enough, the cursor based stuff I've wrapped doesn't really provide much more than the current element, so haven't seen the need. If it truly is an indexable collection or similar, then sure.

    ReplyDelete
  9. François Piette Can you try the comments now?  I think I have them working with IE, but I can never tell for sure.  ;-)

    ReplyDelete
  10. François Piette IE should be banned.  I cannot believe how much time we waste trying to work our web applications around IE's "standards".  We're actually considering telling clients that for non public-facing applications, we'll only support Chrome, FireFox, and Safari.  If they insist on IE, they pay extra.  Sorry for thread drift, but I just came off a late night of battling IE issues.

    ReplyDelete
  11. Kevin --

    Can you give comments-with-IE a look on my site?  I implemented a fix recommended by the BlogEngine team.....

    ReplyDelete
  12. Just tried IE (9.0.8112.16421) from my W7 box and see the same problem as described by François Piette

    ReplyDelete
  13. That's weird, because I can add comments as you can probably see --

    ReplyDelete
  14. Nick Hodges do you nean you can add comments using IE9? I can add comments using Chrome but not IE9. I tried from 2 different computers (Win7 and W2K8). Both fails.

    ReplyDelete
  15. I can with IE10 -- but I couldn't before I put in the fix.  Great.

    ReplyDelete

Post a Comment