On Fri, 11 Feb 2022 at 02:13, BlindAnagram <blindanag...@nowhere.org> wrote: > > Is there any difference in performance between these two program layouts: > > def a(): > ... > def(b): > c = a(b) > > or > > def(b): > def a(): > ... > c = a(b) > > I would appreciate any insights on which layout to choose in which > circumstances. >
Great question! The difference is that, in the second case, a() isn't available anywhere else. So the real question is: Is that good or bad? Does it make sense to call a() from outside of your second function, even for testing? If so, maybe name it _a() so it's private, but keep it global. Does a() need a lot of information from the context of your second function? If so, it's easier to have a closure, with one function inside another. Both styles make sense, and your question is well put: it's a design decision with no "right" or "wrong", just different choices with different implications. ChrisA -- https://mail.python.org/mailman/listinfo/python-list