5 ms·
It's worth mentioning that JavaScript has had this feature for a while now, most likely inspired by C#. https://developer.mozilla.org/en-US/docs/Web/JavaScript
by steve_taylor 4y ago
It's worth mentioning that JavaScript has had this feature for a while now, most likely inspired by C#.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Generator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- agumonkey 4y agoI don't know the timeline but it's interesting how c#, js, python, php and maybe others got generators around the same period.
- dragonwriter 4y ago> I don't know the timeline but it's interesting how c#, js, python, php and maybe others got generators around the same period. AFAICT, not really all that close in time: Python 2.2 (2001) .NET 1.1 (2003) PHP (2012-ish, based on RFC date) JS ES2015 (2015) [though nonstandardized impls in some engines prior]
- steve_taylor 4y agoPretty sure IEnumerable was part of the .NET 2.0 release in 2005. https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-version-history#c-version-20 https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csh...
- bzxcvbn 4y agoI don't see how you get to that conclusion. These release notes mention enumerators: > C# version 2.0 brought iterators. To put it succinctly, iterators let you examine all the items in a List (or other Enumerable types) with a foreach loop. Having iterators as a first-class part of the language dramatically enhanced readability of the language and people's ability to reason about the code. The implicit assumption in that sentence is that enumerables existed before iterators.
- SideburnsOfDoom 4y agoIEnumerable<T> was in the 2.0 release - it's generic, there were no generics in 1.0 But the non-generic IEnumerable and foreach syntax was in from 1.0 https://docs.microsoft.com/en-us/dotnet/api/system.collections.ienumerable https://docs.microsoft.com/en-us/dotnet/api/system.collectio... "Yield return" generators is also from 2.0
- steve_taylor 4y agoYeah, OK. I was wrong about IEnumerable, although the original post is also about the features that make IEnumerable great, such as yield return.
- SideburnsOfDoom 4y ago"Yield return" arrived in C# 2, in 2005 https://stackoverflow.com/questions/53190388/in-which-version-of-net-the-yield-return-syntax-was-added https://stackoverflow.com/questions/53190388/in-which-versio... https://en.wikipedia.org/wiki/C_Sharp_2.0 https://en.wikipedia.org/wiki/C_Sharp_2.0
- psychoslave 4y agoFor Ruby: - Enumerator are documented as soon as 1.9.1[1] in 2009[2] - Enumerable are already present in 1.8.6[3] released in 2006[4], and the matching source code is easily trackable on Github through enumerable.c[5] back to 2005. The Git repository won’t bring any meaningful information before that on this file, due to the import from SVN if I well understand. There is also an enum.c file, but I’m not versed enough in Ruby code base to tell what is it about. [1] https://ruby-doc.org/core-1.9.1/Enumerator.html https://ruby-doc.org/core-1.9.1/Enumerator.html [2] https://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-released/ https://www.ruby-lang.org/en/news/2009/01/30/ruby-1-9-1-rele... [3] https://ruby-doc.org/core-1.8.6/Enumerable.html https://ruby-doc.org/core-1.8.6/Enumerable.html [4] https://www.ruby-lang.org/en/news/2007/03/12/ruby-1-8-6-released/ https://www.ruby-lang.org/en/news/2007/03/12/ruby-1-8-6-rele... [5] https://github.com/ruby/ruby/commits/master?after=78425d7e74887b57ee15e6b8933bd3878db6a888+314&branch=master&path%5B%5D=enumerator.c&qualified_name=refs%2Fheads%2Fmaster https://github.com/ruby/ruby/commits/master?after=78425d7e74...
- dragonwriter 4y ago> Enumerator are documented as soon as 1.9.1[1] in 2009[2] And Generator is present in 1.8 (though I can't determine how early in the 1.8 series). Same basic function, slightly different API (and Generator used Continuations under the hood, while Enumerator uses Fibers, which improved performance and, in theory, implementability in alternative Rubies which didn't all support Continuation, which was one motivation for moving Continuation out of the core language in 1.9.)
- agumonkey 4y agoI'm very confused, for some reason I read about python generators way later than 2001 (2010?). Maybe they upgraded some syntax and it made me read about it.
- dragonwriter 4y ago> I'm very confused, for some reason I read about python generators way later than 2001 (2010?). Maybe they upgraded some syntax and it made me read about it. After generators were introduced themselves, Generator expressions were added in 2.4, coroutine support with yield as an expression in 2.5, “yield from” to delegate to a subgenerator in 3.3. So, yeah, that's plausible.
- int_19h 4y agoIt's interesting how direction of feature flow changes over time. In 2005, C# got iterators from Python; in 2015, Python got async/await from C#.
- sparsely 4y agoIt lacks the strong standard lib support that c# has sadly, and the open source alternatives are a really mixed bag in terms of quality or complexity of usage.