2 comments

  • anthonj16 minutes ago
    I don&#x27;t really get the point of the article. Even if I knew little about python, would be it surpsing that a language with no real basic types is probably abstracting a lot?<p>Even a simple i=0, i=i+1 is &quot;hiding&quot; a lot in python then.
    • PaulDavisThe1st0 minutes ago
      But it&#x27;s not a Python thing. Rust is noted below, and there&#x27;s also C++.<p><pre><code> std::container&lt;T&gt; container; for (std::container&lt;T&gt;::iterator i = container.begin(); i != container.end(); ++i) { ...} auto iter = container.begin(); while (iter != container.end()) { ...; ++iter; } for (auto const &amp; t : container) { ... }</code></pre>
  • WhyNotHugo41 minutes ago
    &#x27;for&#x27; loops in Rust do the same: they create an iterator and then iterate over that.<p>You can write the exact same loop with `let mut iter = v.iter(); while Some(x) = iter.next()`.<p>&#x27;for&#x27; loops in Rust are <i>purely</i> syntax sugar, and I somewhat wish they didn&#x27;t exist. They provide you two ways of doing the same thing, but one of them hides the details from you. Having &#x27;for&#x27; as a keyword is nice for folks coming from other languages, but then it hides the possibility of other interesting usages, like cloning an iterator inside a loop.
    • kevinmgranger4 minutes ago
      It should be `v.into_iter()`, and that distinction matters because of ownership &#x2F; move semantics.<p>It just so happens that for most collections, `IntoIter` is also defined for references to them, which typically gives you the same behavior that `.iter()` would give.
    • tialaramex28 minutes ago
      It&#x27;s true that they&#x27;re just sugar but Rust does explain how the for-in loop de-sugars and you&#x27;ve over-simplified considerably. Your syntax also doesn&#x27;t quite work.<p>The value is in idiom, turning everything into loop expressions (The &quot;while&quot; keyword is also just sugar, Rust&#x27;s only fundamental loop is named loop) makes it harder to discern what&#x27;s actually going on.<p>If you want to clone the iterator in some cases rather than consuming it, that <i>should</i> look different so that reviewers will see what you&#x27;re up to.
    • Martinussen32 minutes ago
      Is &quot;hiding&quot; in the sense that you just need to have read the docs or know how the language works at a pretty basic level really a problem, or even a negative? I would certainly say that the readability and clarity on the form of loop being used is a bigger win, either way.
    • bigfishrunning34 minutes ago
      Which is funny, because whenever I encounter a language for which `for` *doesn&#x27;t* work this way it feels antiquated. I do however wish another keyword was used in many cases, becuase `for` in C and Go is so much different then `for` in Rust or Python. I think the higher-level case (Rust and Python) should really use a word like `foreach` or maybe something compeletely different like `itr`, although I get that they want to &quot;look&quot; more like C