<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, May 1, 2016 at 7:05 PM, Chris Angelico <span dir="ltr"><<a href="mailto:rosuav@gmail.com" target="_blank">rosuav@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">On Mon, May 2, 2016 at 11:36 AM, Steven D'Aprano <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br>
> On Sun, May 01, 2016 at 09:25:17PM -0400, Random832 wrote:<br>
><br>
>> Is there any reason not to simply implement a performance optimization<br>
>> for the normal syntax?</span><br clear="all"></blockquote></div><br>If the variable is already a local, there's not much of a performance win to be had, since replacing a LOAD_FAST with a DUP_TOP doesn't make much of a difference (and if it is anything else the optimization isn't safe, as you already explained).<br><br></div><div class="gmail_extra">HOWEVER... I doubt that this is what the OP is after. I also don't think they're really after having to write less. I think what they want is to express the IDEA of doing various things to/using attributes of a specific object. (OK, I will now stop using all caps. :-)<br><br></div><div class="gmail_extra">Like Steven, I think it's a reasonable idea.<br><br>The idea of using a leading dot is good. There are some edge cases around nesting but I think they can be dealt with.<br><br></div><div class="gmail_extra">I have also seen plenty of code that would benefit from this idiom, e.g. code that repeats something like `team.users[i]` several times in one call -- I imagine the author just didn't want to interrupt their flow by putting it in a local variable.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">But unlike Steven, I'm still lukewarm at most and would currently vote -0. Does this feature find a lot of use in other languages? If so, is the code using it typically clearer than the alternative?<br><br></div><div class="gmail_extra">If a coder currently writes<br><br>team.evict_user(team.users[i].uid, team.users[i].email, "Bye bye")<br><br>because they can't be bothered to write<br><br></div><div class="gmail_extra">user = team.users[i]<br></div><div class="gmail_extra">team.evict_user(user.uid, user.email, "Bye bye")<br><br></div><div class="gmail_extra">then would they bother writing this instead?<br><br></div><div class="gmail_extra">using team.users[i]:<br> team.evict_user(.uid, .email, "Bye bye")<br><br></div><div class="gmail_extra">And is that really clearer? Even if it's used often enough that people will recognize it, the dot is an awfully small character and easily missed (on my screen there are smudges larger than a dot in the standard font :-).<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Plus there's the cost of the extra indent. Sure, omitting the user variable probably makes the line shorter, but what if there are other lines in the same block that don't use it? I've seen plenty of code doing something less readable to avoid an extra indent (which might require breaking lines that would otherwise just fit).<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>