Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #9117 > unrolled thread
| Started by | Eric Snow <ericsnowcurrently@gmail.com> |
|---|---|
| First post | 2011-07-09 15:28 -0600 |
| Last post | 2011-07-09 19:28 -0600 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.python
What makes functions special? Eric Snow <ericsnowcurrently@gmail.com> - 2011-07-09 15:28 -0600
Re: What makes functions special? Ben Finney <ben+python@benfinney.id.au> - 2011-07-10 08:41 +1000
Re: What makes functions special? Eric Snow <ericsnowcurrently@gmail.com> - 2011-07-09 17:16 -0600
Re: What makes functions special? Ben Finney <ben+python@benfinney.id.au> - 2011-07-10 10:38 +1000
Re: What makes functions special? Eric Snow <ericsnowcurrently@gmail.com> - 2011-07-09 19:28 -0600
| From | Eric Snow <ericsnowcurrently@gmail.com> |
|---|---|
| Date | 2011-07-09 15:28 -0600 |
| Subject | What makes functions special? |
| Message-ID | <mailman.805.1310246946.1164.python-list@python.org> |
A tracker issue [1] recently got me thinking about what makes functions special. The discussion there was regarding the distinction between compile time (generation of .pyc files for modules and execution of code blocks), [function] definition time, and [function] execution time. Definition time actually happens during compile time, but it has its own label to mark the contrast with execution time. So why do functions get this special treatment? Functions are a special case in Python for providing a more optimized execution of a code block in pure Python code. And how is that? When the function is defined, a code object is generated for the function body along with a few "static" details that will be used during execution. No other objects have code objects. No other objects in Python have this special optimization. Maybe I am missing something, or maybe it is super obvious, but isn't this a critical point? Is it just a CPython implementation detail that code objects should provide an optimization, or is it a specification of the language? From the docs, the code objects in of function objects are the latter, but the optimization expectation is not clearly indicated. Are there other motivations behind code objects that I am missing? Am I wrong about the optimization expectation? Thoughts? -eric [1] http://bugs.python.org/issue12374
[toc] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2011-07-10 08:41 +1000 |
| Message-ID | <87sjqfgjqg.fsf@benfinney.id.au> |
| In reply to | #9117 |
Eric Snow <ericsnowcurrently@gmail.com> writes: > A tracker issue [1] recently got me thinking about what makes > functions special. As you describe, functions are special for your scenario because a function definition needs to result in executable code as an object. > Definition time actually happens during compile time, but it has its > own label to mark the contrast with execution time. So why do > functions get this special treatment? You answer this question. > No other objects have code objects. No other objects in Python have > this special optimization. Yes. The two facts are directly related. > Maybe I am missing something, or maybe it is super obvious, but isn't > this a critical point? What is the crisis (“a stark change from one state to another”) that you're referring to by “a critical point”? Yes, functions are different and are treated differently. What's your question? > From the docs, the code objects in of function objects are the latter, > but the optimization expectation is not clearly indicated. Are there > other motivations behind code objects that I am missing? Am I wrong > about the optimization expectation? What optimisation expectation? > Thoughts? I think yours need to be expressed more explicitly; I'm not seeing the issue that concerns you. -- \ “The reason we come up with new versions is not to fix bugs. | `\ It's absolutely not.” —Bill Gates, 1995-10-23 | _o__) | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Eric Snow <ericsnowcurrently@gmail.com> |
|---|---|
| Date | 2011-07-09 17:16 -0600 |
| Message-ID | <mailman.807.1310253381.1164.python-list@python.org> |
| In reply to | #9119 |
On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney <ben+python@benfinney.id.au> wrote: > Eric Snow <ericsnowcurrently@gmail.com> writes: > >> A tracker issue [1] recently got me thinking about what makes >> functions special. > > As you describe, functions are special for your scenario because a > function definition needs to result in executable code as an object. > >> Definition time actually happens during compile time, but it has its >> own label to mark the contrast with execution time. So why do >> functions get this special treatment? > > You answer this question. > >> No other objects have code objects. No other objects in Python have >> this special optimization. > > Yes. The two facts are directly related. > >> Maybe I am missing something, or maybe it is super obvious, but isn't >> this a critical point? > > What is the crisis (“a stark change from one state to another”) that > you're referring to by “a critical point”? > > Yes, functions are different and are treated differently. What's your > question? > >> From the docs, the code objects in of function objects are the latter, >> but the optimization expectation is not clearly indicated. Are there >> other motivations behind code objects that I am missing? Am I wrong >> about the optimization expectation? > > What optimisation expectation? > >> Thoughts? > > I think yours need to be expressed more explicitly; I'm not seeing the > issue that concerns you. > My point is that functions are special in Python because they provide a built in optimization via the special execution of code objects. I would like to know if it is really that big a deal, and if the optimized execution of code objects is a CPython implementation detail or a specification of the language. -eric > -- > \ “The reason we come up with new versions is not to fix bugs. | > `\ It's absolutely not.” —Bill Gates, 1995-10-23 | > _o__) | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list >
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2011-07-10 10:38 +1000 |
| Message-ID | <87mxgngebf.fsf@benfinney.id.au> |
| In reply to | #9120 |
Eric Snow <ericsnowcurrently@gmail.com> writes: > On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney <ben+python@benfinney.id.au> wrote: > > Eric Snow <ericsnowcurrently@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. > 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. > 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
[toc] | [prev] | [next] | [standalone]
| From | Eric Snow <ericsnowcurrently@gmail.com> |
|---|---|
| Date | 2011-07-09 19:28 -0600 |
| Message-ID | <mailman.812.1310261284.1164.python-list@python.org> |
| In reply to | #9123 |
On Sat, Jul 9, 2011 at 6:38 PM, Ben Finney <ben+python@benfinney.id.au> wrote: > Eric Snow <ericsnowcurrently@gmail.com> writes: > >> On Sat, Jul 9, 2011 at 4:41 PM, Ben Finney <ben+python@benfinney.id.au> wrote: >> > Eric Snow <ericsnowcurrently@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 >
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web