3 ms·
Nice article! I agree with many of the points. If I know the Julia community well enough, criticism like this leads to constructive discussion and eventual impr
by stellalo 5y ago
Nice article! I agree with many of the points. If I know the Julia community well enough, criticism like this leads to constructive discussion and eventual improvement.
One section I don’t get is that about the iteration protocol. It seems like the author is unhappy about the state being passed around, and the “implicit” trait methods one should implement.
The former point appears to be a consequence of the lack-of-object-orientation (which is by design) while keeping object attributes vs state separate wherever possible (which is arguably a good thing in general); I don’t see how else this can be done in a language that only has structs and functions, honestly. Also, the fact that iterators can be themselves stateful is something that can happen in Python too (one is just “expected” not to hold state information inside Iterable types, but there’s no guarantee of that by just looking at the type). This seems hard to avoid. Maybe a trait could be used in Julia to provide this information about an iterator type?
The latter is the same problem as “implicit traits” highlighted in other sections of the article, so not really anything specific to the iteration protocol.
- jakobnissen 5y agoIndeed, the latter problem is the same as implicit traits. For the former, you can absolutely do it without having object-orientation or anything like that. Simply lower the iterator protocol to ``` itr = iterator(x) while (i = next(itr)) !== nothing # stuff end ``` Then `itr` can be mutable, even when `x` isn't. This is what most modern languages does, and it solves all the problems I mentioned, since the state is stored in the mutable iterator, while at the same time, `x` can be unaffected. Read more here: https://mikeinnes.github.io/2020/06/04/iterate.html https://mikeinnes.github.io/2020/06/04/iterate.html
- stellalo 5y agoWell, to be honest I still don’t understand the difference: they seem to me like two different styles of structuring the same kind of logic. In fact, the linked list example in the referenced article from Mike Innes I don’t find very convincing, stated as it is: I would like to see that example concretely, to understand how the current Julia protocol would fall short there (“leak”). Same for the `zip` example in the OP here: I’m not sure the Python `itr = iterate(xs)` kind of protocol makes it any simpler. But I’m on holiday and cannot try it out right now—I owe you one here :-)