Re:Iterator patterns in Go
by i_have_to_speak on Sunday September 08, 2013 @12:33AM
(#6347844)
Seriously? Using a green thread is a pattern for iteration over an array? Or that creating a new function object per iteration is efficient? The "patterns" 2 & 3 listed in the article are grossly inefficient to be considered suitable to implement fixed or dynamic iterators.
[ Parent
| on HN ]
To build on thrownaway2424's response, the point in the article was to demonstrate the pattern for building the iterator. Very simply structured data helps do that. In reality you'd probably be iterating over a more complicated data structure, usually where the iteration requires knowledge of the data structure that should be considered private to the implementation.
Re:Iterator patterns in Go
by thrownaway2424 on Sunday September 08, 2013 @12:39AM
(#6347853)
Sometimes raw performance is not really called for. A lot of programmers are looking for ways to, for example, iterate over lots of different kinds of things that all provide the interface to do so, regardless of their actual types or the details of their allocation.
Sure, if you're about to iterate over a terabyte of double-precision height map data or something like that, please use an array.
Re:Iterator patterns in Go
by i_have_to_speak on Sunday September 08, 2013 @01:06AM
(#6347888)
Without such advice, that article is dangerous. A "lot of programmers" are going to read that and assume these patterns differ between them only in terms of "performance" which equates to "ns/op".
Also, I wouldn't use an array to iterate over a terabyte of double-precision height map -- have you tried that? I have, kind of. In a genome sequence visualization application. Try it sometime. It's fun.