[Python-ideas] Inline Functions - idea

spir denis.spir at gmail.com
Thu Feb 6 14:07:41 CET 2014


On 02/05/2014 03:32 PM, Alex Rodrigues wrote:
> Hi everyone,
> This is my first time on the Python mailing lists. I've been learning a lot about how python is run recently and today I thought I ran across an idea which might create in interesting discussion.Today I was writing a piece of software where I had a block of code that would take a bunch of local variables, apply some transformations to them and then output them as a a string to a log. Then I realized that I actually wanted to reuse this code in multiple locations - there were multiple cases where I might need to do this. My natural inclination was to write a function in order to maintain DRY programming. This was prohibitively challenging, however, since the code itself interacted with lots of variables in the namespace. The number of arguments to the function would have to be very large and possibly would change on a fairly regular basis.This seems like a fairly common problem in programming, having a piece of code which is both reused and heavily integrated with the namespace makin
g it necessary to use copy-paste. As a solution to this I propose the idea of an inline function. An inline function would run in it's parent's namespace instead of creating a new one. This would allow you to avoid passing back and forth tons of values while still maintaining DRY code.

Do you really mean "parent", or instead "caller". If parent, then it's a closure 
function. If caller, I guess you are proposing to introduce dynamic scoping to 
python, which uses lexical scoping [*]. Dynamic scoping is (as I understand it) 
when variables of the caller scope are used in a called procedure; which seems 
to be what you need, unless I misunderstand and you really mean parent scope 
(but this does not seem to match your use case explanations).

d

[*] see:
https://en.wikipedia.org/wiki/Lexical_scoping#Lexical_scoping_vs._dynamic_scoping





More information about the Python-ideas mailing list