[Python-ideas] Definition Symmetry
Ned Batchelder
ned at nedbatchelder.com
Fri Feb 1 17:43:55 CET 2013
On 2/1/2013 12:21 AM, Jason Keene wrote:
> Both class and function definitions produce callable objects that are
> assigned to a name with nearly identical syntax. I don't think your
> analogy with import/break statements is valid. Additionally, both
> definitions produce very similar byte codes:
>
> 3 MAKE_FUNCTION 0
> 6 STORE_FAST 0 (my_func)
>
> 9 MAKE_FUNCTION 0
> 12 CALL_FUNCTION 0
> 15 BUILD_CLASS
> 16 STORE_FAST 0 (MyClass)
>
> The only argument I see for requiring empty parens in function
> definitions is a historical one.
That's because you're ignoring the main one: function calls require
parens, so function definitions also require them.
--Ned.
>
> On Thursday, January 31, 2013, Ben Finney wrote:
>
> Jason Keene <jasonkeene at gmail.com <javascript:;>> writes:
>
> > In a way they do the same thing, they both create an object
> > (function/class) from a suite and assign it to the name given
> after the
> > keyword (def/class). Sure they do totally different things with
> the suite
> > in creating the object, but in essence it's a name assignment.
>
> In a way, 'import' and 'break' do the same thing, they trigger the
> compiler to compile a particular set of code bytes. Sure the code
> bytes
> do totally different things, but in essence it's a statement.
>
> Less facetiously: You can blur your vision as much as you like to make
> 'class' and 'def' look similar, but that doesn't diminish the
> importance
> of the distinctions you're ignoring.
>
> --
> \ "Always do right. This will gratify some people, and
> astonish |
> `\ the rest." ---Mark
> Twain |
> _o__) |
> Ben Finney
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org <javascript:;>
> http://mail.python.org/mailman/listinfo/python-ideas
>
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130201/7478cded/attachment.html>
More information about the Python-ideas
mailing list