Open VBAndCs opened 5 years ago
Any response?
Perhaps because very few people actually write Iterators?
I think I can count on two fingers the number of iterators I've written in the last 20 years. But I've done a lot of inheriting from base classes that have already implemented them for me, so I'm not doing it myself.
That said, having thought about it for very few minutes, that I think that the semantics are different enough that it's not unreasonable that Iterators be considered a new kind of method (discrete from procedures/subs and functions), and that they should Yield their values, where Functions should Return their value. Note that an iterator by definition yields multiple values, and a function returns exactly one (which may be a collection or IEnumerable, but that's another discussion, I think).
@pricerc I wrote this as a general reply #404 :) Thanks.
This may not be an urgent proposal, but it is a logical one and a syntactic suger. Iterator should be an independent block not a function. One obvious reason, it they don't work in the same way, nor use the same return instruction! For example, this iterator will not compile because the return keyword is not allowed, although it seems as perfect function that should work:
So, I ask to define Integrators like this:
This is clearer than Iterator Function definition , and is better in lambdas because the elimination of the long word
Function
:So now, we have Sub, Function, and Iterator blocks.
This change will not break any code, because the old
Iterator Function
syntax will still working, but VB editor should change it to the 'Iterator' syntax once the code file is opened. Any newIterator Function
will be changed instantly toIterator
.Note: There is no such issue in C#, since there is no Function, end function keywords. So, there was no real duality to keep between the two languages when the Iterator keyword was added.