What makes functions special?
Eric Snow
ericsnowcurrently at gmail.com
Sat Jul 9 21:28:02 EDT 2011
On Sat, Jul 9, 2011 at 6:38 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
> Eric Snow <ericsnowcurrently at gmail.com> writes:
>
>> On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney <ben+python at benfinney.id.au> wrote:
>> > Eric Snow <ericsnowcurrently at gmail.com> writes:
>> >> No other objects have code objects. No other objects in Python have
>> >> this special optimization.
>> >
>> > Yes. The two facts are directly related.
> […]
>
>> > Yes, functions are different and are treated differently. What's
>> > your question?
>>
>> My point is that functions are special in Python because they provide
>> a built in optimization via the special execution of code objects.
>
> Functions are special because they define a code object.
>
Right. But the point is that the code objects (in CPython at least)
allow a special execution of the function body. What does that
special execution give us? I am guessing a sufficient performance
increase. Is there anything else? And do other Python
implementations do anything special with code objects?
I am not questioning why it was done a certain way, but rather trying
to understand how Python works.
>> I would like to know if it is really that big a deal
>
> Is *what* really that big a deal?
>
> Perhaps this could be clearer if you'd describe what it is that
> surprises you, and how you'd expect it to be different.
>
I don't have any unexpected failure that I ran into or anything like
that. I am just trying to learn more about the ins and outs of Python
and that tracker issue got me thinking. And I know that there are
plenty of people on this list that know a lot more about Python than I
do. :) So I thought I would ask (in my own obscure way) if I was
understanding the definition/execution model correctly. Sorry for any
confusion.
-eric
>> and if the optimized execution of code objects is a CPython
>> implementation detail or a specification of the language.
>
> I don't know that it's a specification. But functions result in code
> objects, and other statements don't; I am not seeing why treating them
> differently is surprising.
>
> --
> \ “I see little commercial potential for the Internet for at |
> `\ least ten years.” —Bill Gates, 1994 |
> _o__) |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list