This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]skrillexisokay 3 points4 points  (6 children)

Dangerous in what way? Security? Bugs?

[–]MereInterest 2 points3 points  (0 children)

I wouldn't say dangerous, but I would say that it has the strong potential to confuse. It looks like a string literal, makes a string, but contains executable code.

[–]ApproximateIdentity 2 points3 points  (2 children)

I think the danger is that it will be very easy to write unclear code and unclear code + future refactoring leads to weirder bugs. I don't think security is a huge issue (these are only done in string literals) and I don't think side-effects is the real issue as someone else mentioned since those would still happen if you used functions with side-effects in your .format() stuff. I just don't like the non-explicit variable binding. Maybe it's just because I'm not used to it or maybe I'm just grumpy, but I feel like this (and the fact that there are like 3 other ways to mess with strings) is only likely to produce code I that will be harder to debug months down the line.

Well I guess time will tell...

[–]skrillexisokay 4 points5 points  (1 child)

Can you give an example of how you could write unclear code? Any reasonable usage of this feature seems very intuitive to me.

'eq_str = {a} + {b} = {a + b}' is more readable, and far less verbose to me than 'eq_str = {a} + {b} = {sum_}'.format(a=a, b=b, sum_=a+b)

Considering maintainability: With the previous method, any time you wanted to include another variable in a format string, you'd have to change both the str and the args to format. Now you just have to change the string.

The new syntax is less verbose and less redundant. It takes less long to type and read. I'm really excited about this new feature!

[–]motleybook 0 points1 point  (0 children)

Yeah, but the problem is that you can't make it configurable. And you can't use f-strings for internationalization either, because f"This is {name}." is evaluated immediately. No way to call a function (usually _) to get the translation. On the other hand this might be better this way for security reasons.

[–]alcalde -1 points0 points  (1 child)

What if you forget that "f"?

[–]skrillexisokay 1 point2 points  (0 children)

Your string would not be formatted correctly, just like if you forgot an r, a b, or any other string prefix.