Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list
On 10/02/2022 21:43, Friedrich Rentsch wrote: I believe to have observed a difference which also might be worth noting: the imbedded function a() (second example) has access to all of the imbedding function's variables, which might be an efficiency factor with lots of variables. The access is

Re: Global VS Local Subroutines

2022-02-10 Thread Marco Sulla
I agree with Chris. I don't know if it was already written: if you want a local function for speed reasons, you can use the classic approach of a main function. -- https://mail.python.org/mailman/listinfo/python-list

Re: Global VS Local Subroutines

2022-02-10 Thread Friedrich Rentsch
I believe to have observed a difference which also might be worth noting: the imbedded function a() (second example) has access to all of the imbedding function's variables, which might be an efficiency factor with lots of variables. The access is read-only, though. If the inner function writes

Re: Global VS Local Subroutines

2022-02-10 Thread Eryk Sun
On 2/10/22, BlindAnagram wrote: > > This is exactly what I felt too but I then wondered if the code was > recreated dynamically or was static with just a reference being created > on each invocation of the parent. The overhead in this case would be > negligible. But then I thought 'what about the

Re: Global VS Local Subroutines

2022-02-10 Thread BlindAnagram
On 10/02/2022 16:52, Rob Cliffe wrote: On 10/02/2022 12:13, BlindAnagram 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 wh

Re: Global VS Local Subroutines

2022-02-10 Thread Chris Angelico
On Fri, 11 Feb 2022 at 03:57, Rob Cliffe via Python-list wrote: > But of course, performance is not the only consideration, as per Chris > Angelico's answer. Yep. In fact, I'd say that performance is the least significant consideration here; do what makes sense. The time difference will be neglig

Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list
On 10/02/2022 12:13, BlindAnagram 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 circumsta

Re: Global VS Local Subroutines

2022-02-10 Thread BlindAnagram
On 10/02/2022 15:20, Chris Angelico wrote: On Fri, 11 Feb 2022 at 02:13, BlindAnagram 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

Re: Global VS Local Subroutines

2022-02-10 Thread Chris Angelico
On Fri, 11 Feb 2022 at 02:13, BlindAnagram 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

Global VS Local Subroutines

2022-02-10 Thread BlindAnagram
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. -- https://mail.python.org/mailman/l