Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iterators #8

Open
weltkante opened this issue Feb 8, 2016 · 0 comments
Open

Iterators #8

weltkante opened this issue Feb 8, 2016 · 0 comments

Comments

@weltkante
Copy link

In your post about safe native code you drop a line about the C# enumerable/enumerator design beign a bad decision and that you had a better solution.

IEnumerator requires two interface dispatches simply to extract the next item! Compare that to C++ iterators which can compile down a pointer increment plus dereference. Many of these problems could be addressed simply with better library designs.

While I agree that MoveNext and Current in C# could be merged into a single call you're not really comparing the same thing are you? Iterators in C++ are the equivalent to the handwritten C# enumerator structs, which could (theoretically) be optimized and inlined pretty well, too, and certainly have no interface dispatches either.

As far as I know C++ doesn't have modular iterators which can be exported from a component and consumed by another. Creating modular code in a simple way is the major advantage of the C# enumeration protocol. As far as I know (but I may be missing something) C++ doesn't have any concept of how to export an iterator from one library and consume it from another which isn't in the same source module. You have to come up with your own interfaces and iteration protocol and if its modular you probably won't get around virtual interface method invocation either, I think. Especially if you combine it with generics and collections.

Our final design for enumeration didn’t even invole interfaces at all.

I'd love to hear a bit more about that, as I cannot imagine how that is possible. Even if its not a full blog post but just some hints at how your iteration design looked like.

Anyways thanks a lot for all these posts, it's awesome to have a peek at what could be possible with different language design. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant