Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This proposal doesn't affect security in any way. It's just syntactic sugar.

Instead of writing this:

    'My name is ' + format(name) + ' my age next year is ' + format(age+1)
or

    'My name is {name}, my age next year is {age}'.format(name=name, age=age+1)
You just write

    f'My name is {name}, my age next year is {age=1}'
It's shorter, it's more readable and more convenient. I can't wait for this PEP to be accepted.

Edit: Fixed small errors in the examples.



First of all, I don't think you can do {age+1} in a string right now.

But you can use string placeholders when used with format function. That should take take of this use case. So no need to add another syntactic sugar to make it more convenient.

It is already as simple as possible. Let us not try to simplify it further.

I will be horrified and very worried about the direction that the language has taken if this pep gets accepted.


This perspective is so interesting to me. You say the version using `.format` is "as simple as possible", but the interpolated version seems clearly simpler to me, because it eliminates the redundancy in the placeholders. What's the disconnect here?


> but the interpolated version seems clearly simpler to me. What's the disconnect here?

The disconnect is this. An explicit list of variables to use for interpolation is not redundancy. Because the placeholders does not, by themselves, refer to anything. Placeholders are just holes and only have a meaning in the context of formatting functions. And even in them, they does not refer to a local variables, even when they share a common name. So when you use .format() function, you are actually saying, "here is a string with some named holes. Fill the hole named 'A' with the value from variable 'A', the hole named 'B' with the value from variable 'B'.

So hole 'A' and variable 'A' are different things even if they share the same name.

Now, the simplicity argument.

Every thing should be made as simple as possible. But not simpler. Why not? Because when you simplify further, you are paying a cost (often not apparent initially), some times in clarity, sometimes in correctness and so on. The pigeonhole principle.

In our case, we can further simplify the process by adding an implicit mapping from named placeholders to local variables. When you do so, you are adding something implicit. The costs of which might not be apparent at this point..

So this pep is strapping on something to the whole language, to slightly simplify this one use case. Which is why I said that it is trying to simplify it further than it is possible.


edit: Deleted my response because this is a bikeshed. You prefer placeholders, I prefer interpolations, it's totally subjective and there's little point debating it!


You're right, you can't do {age+1} in a string right now. I just edited to fix it.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: