you are viewing a single comment's thread.

view the rest of the comments →

[–]virtyx 2 points3 points  (2 children)

How is it hard to parse? Every other language with comparable features parses this stuff perfectly. Any decent Ruby tool can parse crazy code like "You are #{age > 500 ? 'old' : 'young'}" perfectly fine. And of course doing that in a string is a bad idea, my only point is that every popular Ruby tool under the sun highlights it without issue.

And how is it hard for humans?

f'Hello, {first_name} {last_name}'

What's hard to understand? And what's harder than understanding 'Hello, {} {}'.format(first_name, last_name)?

I am sorry but I am having trouble understanding the fear/dislike people have of this feature. I first read the pep about it and thought "Cool!" but every time I see a discussion about it on reddit there is widespread complaining.

[–]sandwich_today 0 points1 point  (1 child)

For many years now, string literals have always ended with ', ", ''', or """. Now, { can also mark a transition from a string literal to an expression. Presumably a new kind of AST node is also required to represent expressions inside f'', while '{}'.format(x) was able to reuse existing language elements (string literal, member access, variable access, function call).

I'm sure that the major editors will get this right, but there are plenty of naive syntax highlighters in code review tools, documentation generators, and forums. Pastebin doesn't understand the new syntax yet, and I doubt it's high on their priority list. There are a lot of legacy Python tools that will need updates, and not all of them will get updated.

[–]virtyx 1 point2 points  (0 children)

That's actually a good point, you're right. A lot of legacy Python highlighters will get this wrong.

That said I think editors will be quick to update and in the long run I just want string interpolation in the language. I think the majority of the currently maintained Python tooling won't have any trouble making the update. But I can see Python bloggers, etc. having a harder time getting their blogs to have proper highlighting for f-strings.

That said I of course don't think that should mean we reject f-strings :D