5 comments

  • chubot1 hour ago
    I wasn&#x27;t really familiar with this term, but as another comment here said, the only language I use that doesn&#x27;t have such late binding&#x2F;dynamic dispatch is C<p>i.e. it seems natural in Python and C++ (and Java and Rust …)<p>But I did notice the term &quot;open recursion&quot; in Siek&#x27;s Essentials of Compilation - <a href="https:&#x2F;&#x2F;mitpress.mit.edu&#x2F;9780262048248&#x2F;essentials-of-compilation&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mitpress.mit.edu&#x2F;9780262048248&#x2F;essentials-of-compila...</a><p><i>To make our interpreters extensible we need something called &quot;open recursion&quot;, in which the tying of the recursive knot is delayed until the functions are composed. Objected-oriented languages provide open recursion via method overriding</i><p>---<p>I mentioned that here too, on a thread about a type checker: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=45151620">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=45151620</a><p>To me the open recursion style clearly seems like a better default than VISITORS?<p>You can still REUSE traversal logic, and you don&#x27;t &quot;lose the stack&quot;, as I pointed out in the comment below: <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=45160402">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=45160402</a><p>Am I missing something? I noticed there is a significant disagreement about style, which seems to not have a clear rationale: MyPy uses visitors all over, while TypeScript uses switch statements<p>This is a big difference! It affects nearly every line of code, and these projects have a ton of code ...
  • glhaynes2 hours ago
    This was really helpful and easy to follow. I came across this term the other day in that article that was going around about defining OOP and was a little baffled and thought &quot;uh, I&#x27;ll come back to this&quot;, but this gave me the perspective I needed to get it.
    • jerf1 hour ago
      It&#x27;s one of those things that&#x27;s hard to get for most of us not because we don&#x27;t understand what it is, but that we don&#x27;t understand what <i>not</i> having it is like. Most languages in common use have this.<p>It can be similarly difficult to explain to people what structured programming is, because basically everything is structured programming now. The hard part is understanding what <i>non</i>-structured programming is, so that you can then understand the contrasts, because there is so little experience with it anymore.
  • skybrian1 hour ago
    For an example of a language feature that looks kind of like standard object-oriented inheritance, but isn’t, check out “struct embedding” in Go. Struct embedding gives you the syntax of inheritance and you can even override methods, but for internal self-calls, methods don’t get overridden. (If you wanted to allow that, you’d need to add function pointers or an interface to the struct.)
  • kazinator2 hours ago
    Example of open recursion: add a new object type into a low-level language run time.<p>You implement a garbage traversal routine for it, which recurses over traversing the child objects.<p>The system is open to extension; the garbage collector doesn&#x27;t just have a switch statement to handle all the known objects. It may have that too, but for some object kinds, it dispatches their method.
  • Akronymus2 hours ago
    Am I understanding it correctly that those lambda functions are lexically bound rather than creating closures, in the &quot;Open&quot; section?