mutation is tricky, a whole field of programming language research is built on avoiding mutation
A reasonably large number of the bugs I encounter relate to the order or number of formatting arguments not matching the slots in the format string. It's pretty hard to make that kind of mistake with an fstring.
I don't want it to scream on a missing docstring for every single thing. I do want to be able to use a, b and x as variables. No, this root var is not a constant, don't ask me for uppercase. Etc.
$ pylint pylint_sucks_at_partials.py
************* Module pylint_sucks_at_partials
pylint_sucks_at_partials.py:7:0: C0103: Constant name
"add5" doesn't conform to UPPER_CASE naming style
(invalid-name)
The program in question: #!/usr/bin/env python
""" proving pylint still sucks at partials """
from functools import partial
from operator import add
add5 = partial(add, 5)
if __name__ == '__main__':
import sys
print(add5(int(sys.argv[1]))) if logger.isEnabledFor(logging.DEBUG):
logger.debug(f'{expensive_func()}')Using percent formatting is superior in many ways:
- errors that occur in formatting a message will be logged instead of raising an exception into your application
- error reporting services like Sentry can properly aggregate events
- interpolation won't occur if you don't have the logging level enabled
- it's recommend by the Python docs: https://docs.python.org/3/howto/logging-cookbook.html#use-of...
If `print("{x}")` printed "{x}" in Python 3.5, it shouldn't print something else in a newer version. But `print(f"{x}")` was a syntax error before f-strings, so no code is broken by giving it a meaning.
JavaScript can't interpolate ordinary strings either, for the same reason. You need to use backticks (``).
Thank you for the explanation of the f-strings. I'm pretty sure that migrating old strings to "\{x\}" could be automated but we can't force everybody to migrate their code. There is probably no other way than the one they followed.
The correct way to escape braces in f-strings is with double braces, so f"{{x}}". This is consistent with the way str.format works. f-string syntax is very similar to str.format syntax in general.
It kind of goes to the question: When is a language "finished"?
finished is dead, to put it less mildly.