[Python-ideas] Inline Functions - idea

David Mertz mertz at gnosis.cx
Wed Feb 5 19:17:09 CET 2014


It's hard for me to see the use case for this "inline function" idea.  The
example given is just some code that is repeated within branches of an
'if'; but the obvious thing is to move that repetition outside the if/elif
clauses.

I understand that the example is simplified to present it, but it's hard
for me easily to imagine a case where either using a closure or passing in
'locals()' directly fails to cover everything you are asking for.  I mean,
you did say that passing locals() is "clunky", but it's hard to see how any
function that dealt with the availability of different variables on an ad
hoc basis could really be non-clunky (and that what every inline function
would have to do).


On Wed, Feb 5, 2014 at 7:15 AM, Alex Rodrigues <lemiant at hotmail.com> wrote:

> Hi guys,
>
> A couple more thoughts
>
>    1. As to why I didn't use an "or" in the original example. I am aware
>    that the example doesn't actually need an inline function, but it
>    demonstrates the concept in a simple way (so that it would fit in an
>    email). Most use-cases are more complicated, often the spots where you want
>    to execute the same code are buried inside long, branching logic statements
>    where other things are going on, making restructuring the code much less
>    trivial, if not impossible.
>    2. I had never really considered using closures that way (I haven't
>    really used them much at all), that is extremely cool! It does exactly what
>    I was envisioning as long as you only need it in one spot. If inline
>    function got implemented I'm sure they would steal a lot of code from
>    closures.
>       - The remaining use cases for inline functions are times when you
>       would need the same capabilities in multiple functions (calling in
>       multiple methods of a class for example), or when you wish to define what
>       is essentially a closure at the first level of execution, since closures
>       are not possible when you are not in a function.
>    3. I always knew you could do it the way skip showed, but I feel like
>    that is a bit clunky. This would allow you to do that in a more
>    straight-forward way.
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140205/ab784f87/attachment.html>


More information about the Python-ideas mailing list