<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 19, 2016 at 9:58 AM, João Bernardo <span dir="ltr"><<a href="mailto:jbvsmo@gmail.com" target="_blank">jbvsmo@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span class=""><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 19, 2016 at 12:06 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Every call to namedtuple() creates a new class, which is a very expensive operation. On my machine the simplest namedtuple call taks around 350 usec.<span><font color="#888888"><br></font></span></div><span><font color="#888888"><div></div></font></span></div></div></div></blockquote></div><br></div><div class="gmail_extra"><br></div></span><div class="gmail_extra">Isn't that because the code for namedtuple is using exec instead a more pythonic approach of metaclassing to make it "faster" but taking longer to actually create the class? </div><div class="gmail_extra"><a href="http://bugs.python.org/issue3974" target="_blank">http://bugs.python.org/issue3974</a></div></div></blockquote><div><br></div><div>That's part of it, but no matter how you do it, it's still creating a new class object, you can't get around that. And class objects are just expensive. Any idiom that ends up creating a new class object for each instance that's created is a big anti-pattern.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">Maybe instead of changing namedtuple (which seems to be a taboo), there could be a new anonymous type. Something built-in, with its own syntax.</div></div></blockquote><div><br></div><div>That's essentially what the (x=12, y=16) proposal is about, IIUC -- it would just be a single new type, so (x=12, y=16).__class__ would be the same class object as (a='', b=3.14).<br><br></div><div>But I have serious reservations about that idiom too.<br></div></div><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>