News for hackers. Stuff that matters.
Re:The ancient world before computers had stacks or heaps by mikepurvis on Wednesday April 03, 2024 @12:41PM (#39919642)
The only time I ever do it is for tree walking, and then it's always a private internal function, so like:

    def process_that_tree(my_tree):
      def _handle(node):
        # do the things
        for child in node.children:
          _handle(child)
      _handle(my_tree.root)
The processing can even be brought outside sometimes, or the walker can just become a generator, yielding nodes out to a regular loop doing the actual work. Either way, the recursive part is kept very minimal and easy to reason about.

Obviously for the filesystem these kinds of abstractions exist already in shutil/pathlib/glob, but it still can have a place for dealing with other kinds of hierarchies, like a package dependency tree or the like.

There are no comments on this comment yet.