Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #9117

What makes functions special?

Date 2011-07-09 15:28 -0600
Subject What makes functions special?
From Eric Snow <ericsnowcurrently@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.805.1310246946.1164.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

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

csiph-web