<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Aug 9, 2015 at 11:22 AM, Eric V. Smith <span dir="ltr"><<a href="mailto:eric@trueblade.com" target="_blank">eric@trueblade.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><span style="color:rgb(34,34,34)">I think it has to do with the nature of the programs that people write.</span><br></div></div>
I write software for internal use in a large company. In the last 13<br>
years there, I've written literally hundreds of individual programs,<br>
large and small. I just checked: literally 100% of my calls to<br>
%-formatting (older code) or str.format (in newer code) could be<br>
replaced with f-strings. And I think every such use would be an improvement.<br></blockquote><div><br></div><div>I'm sure that pretty darn close to 100% of all the uses of %-formatting and str.format I've written in the last 13 years COULD be replaced by the proposed f-strings (I suppose about 16 years for me, actually). But I think that every single such replacement would make the programs worse. I'm not sure if it helps to mention that I *did* actually "write the book" on _Text Processing in Python_ :-).</div><div><br></div><div>The proposal just continues to seem far too magical to me. In the training I now do for Continuum Analytics (I'm in charge of the training program with one other person), I specifically have a (very) little bit of the lessons where I mention something like:</div><div><br></div><div> print("{foo} is {bar}".format(**locals()))</div><div><br></div><div>But I give that entirely as a negative example of abusing code and introducing fragility. f-strings are really the same thing, only even more error-prone and easier to get wrong. Relying on implicit context of the runtime state of variables that are merely in scope feels very break-y to me still. If I had to teach f-strings in the future, I'd teach it as a Python wart.</div><div><br></div><div>That said, there *is* one small corner where I believe f-strings add something helpful to the language. There is no really concise way to spell:</div><div><br></div><div> collections.ChainMap(locals(), globals(), __builtins__.__dict__).</div><div><br></div><div>If we could spell that as, say `lgb()`, that would let str.format() or %-formatting pick up the full "what's in scope". To my mind, that's the only good thing about the f-string idea.</div></div><div class="gmail_extra"><br></div>Yours, David...<br clear="all"><div><br></div>-- <br><div class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div>