[Top][All Lists]

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

Re: [Help-bash] make function local

From: Peng Yu
Subject: Re: [Help-bash] make function local
Date: Mon, 20 Apr 2015 15:04:00 -0500

Hi Chet,

>>> 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.

Why do you assume that one only calls each of these functions once?
What if a function is called thousands of time?

The performance difference is 10x different (0.490s vs 0.040s). To me,
this is a huge performance problem.

> (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.

Functions are usually called for more times they are defined.
Therefore, even if the function creation time is acceptable, it
doesn't mean its call time is acceptable.

> 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.

The main point that Linda and I are making is that we suggest add the
local function feature. I believe that we've made the case --- it
makes the code cleaner and run faster.

What makes you reluctant to consider this feature be added? Is it
takes too much time to implement such a feature?


reply via email to

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