Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'cpython': 0.05; 'url:bugs': 0.05; 'distinction': 0.07; 'something,': 0.07; 'python': 0.08; 'defined,': 0.09; 'thoughts?': 0.09; 'tracker': 0.09; 'docs,': 0.16; 'language?': 0.16; 'latter,': 0.16; 'missing?': 0.16; 'that?': 0.19; 'to:name:python-list': 0.19; 'maybe': 0.22; 'discussion': 0.22; 'code.': 0.22; 'expectation': 0.23; 'received:209.85.215.46': 0.23; 'received:mail- ew0-f46.google.com': 0.23; 'code': 0.24; 'modules': 0.25; 'function': 0.26; 'objects': 0.28; 'message-id:@mail.gmail.com': 0.28; 'compile': 0.29; 'object': 0.30; 'definition': 0.30; 'objects.': 0.30; 'subject:?': 0.31; 'pure': 0.32; 'actually': 0.33; 'to:addr:python-list': 0.34; 'there': 0.34; 'clearly': 0.35; 'subject:What': 0.35; "isn't": 0.35; 'optimization': 0.36; 'url:python': 0.37; 'issue': 0.37; 'but': 0.37; 'received:google.com': 0.38; 'received:209.85': 0.38; 'url:org': 0.38; 'execution': 0.38; 'case': 0.39; 'should': 0.39; '[1]': 0.39; 'got': 0.39; 'to:addr:python.org': 0.39; 'missing': 0.40; 'mark': 0.40; 'received:209': 0.40; 'super': 0.62; 'body': 0.63; 'details': 0.65; 'special': 0.67; 'execution.': 0.84; 'special.': 0.84; 'contrast': 0.91; 'obvious,': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; bh=/Jtes5mjaVCUlAQmPhHx/f2ft312w5E6B8VZ0vEd7mM=; b=CvYjlqxYPZvR96EPSBi7wbENN3LOp1JP8Wn5yMpiEWt8SOzVLDqsQ9Wu7nUEy0XdHe WUND2NAV7W2+6SbpM6zoOF7O7fJjlXnIfeuGdIYuq7zIiSY1HlH3WPbv8/gIs38TnJy6 ffv+BnyKostGHe8hvbi8JMiWZIo0OPr42+Odw= MIME-Version: 1.0 Date: Sat, 9 Jul 2011 15:28:58 -0600 Subject: What makes functions special? From: Eric Snow To: python-list Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1310246946 news.xs4all.nl 21758 [2001:888:2000:d::a6]:52468 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:9117 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