Am 18.11.2011 05:34 schrieb Dennis Lee Bieber:
>> def _pass(*args):
>>      pass
>>
>> def long_running_process(arg1, arg2, arg_etc, report = _pass):
>>      result1 = do_stuff()
>>      report(result1)
>
> So this is a call to a function that just returns a None, which is
> dropped by the interpreter...

I'm not sure about this. I think, the call will be executed, but the callee will return immediately. It is different from call being dropped.

Another optimized alternative could be to do

def long_running_process(arg1, arg2, arg_etc, report=None):
    result1 = do_stuff()
    if report: report(result1)

but I think that is too low benefit at the cost of too much readability.

Such a function call is

  2           0 LOAD_FAST                0 (a)
              3 POP_JUMP_IF_FALSE       16
              6 LOAD_FAST                0 (a)
              9 CALL_FUNCTION            0
             12 POP_TOP
             13 JUMP_FORWARD             0 (to 16)

  3     >>   16 ...

as opposed to just

  2           0 LOAD_FAST                0 (a)
              3 CALL_FUNCTION            0
              6 POP_TOP

with a call target of

  1           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE

I don't think that a call is sooo expensive that it would make any noticeable difference.


Thomas

BTW: Sorry, Dennis, for the private mail - I am incapable to use Thunderbird correctly :-(
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to