bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] make function local


From: Chet Ramey
Subject: Re: [Help-bash] make function local
Date: Mon, 20 Apr 2015 11:15:45 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 4/19/15 10:38 PM, Peng Yu wrote:

>> That's the difference: if you're careful with naming and rigorous about
>> your calling conventions, your one-time-use functions are about as close
>> as you can get to local functions in bash, but you have to pay attention
>> to the declaration's side effects.
> 
> There is at least a runtime overhead for having too many unused
> functions that are supposed to be "local" or in your word "lambda".

Maybe so, but this is not the discussion we were having.

> Despite that one can rename supposedly internal functions to names
> that are unlikely to cause name collision via good naming convention,
> it still can incur a significant performance overhead.

I disagree that performance overhead in typical use is `significant'.
This point is more or less identical to the one I discussed Friday in
regards to creating huge numbers of variables.  Who creates 100,000
shell functions in a single script?  The overhead, such as it is, of
creating and calling even 10,000 functions is negligible.

(And the example you chose to illustrate this is not what Linda is
talking about or using.)

> In this sense, I think that it is still necessary to consider make the
> supposedly internal function "local" so that they would not slow down
> function search in the global namespace.

Look, you can make the same argument about function creation at any
scope, since there is one function namespace.  Acceptable performance is
subjective: if the technique that Linda uses for data encapsulation
results in performance that's acceptable for her application, then it's
ok for her to use it.  You are certainly free to use any methodology you
find comfortable and satisfies your constraints.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]