|
|
Subscribe / Log in / New account

Formalizing f-strings

Formalizing f-strings

Posted Jan 11, 2023 11:54 UTC (Wed) by eru (subscriber, #2753)
Parent article: Formalizing f-strings

Nice work, but not sure if this is so useful in real life. f-strings (and similar features in other programming languages) turn the code unreadable, if the expression being expanded is complex (basically anything beyond a variable reference or a very simple expression). Anything more complicated is best handled by introducing auxiliary variables. Or just by using the string concatenation operator.


to post comments

Formalizing f-strings

Posted Jan 11, 2023 17:53 UTC (Wed) by iabervon (subscriber, #722) [Link]

It'll be very useful to be able to do, even if you never keep code that does it: you can copy some complex expression from nearby code into a log message and see what's really happening in the code you're debugging, without a lot of effort making sure to get refactoring right and not disturb the local scope. Then, when you understand what you should really make the code do, you'll check something in that doesn't have the unreadable code.

For that matter, what constitutes "a very simple expression" is really dependent on the language's common idioms and the capabilities of widely-deployed syntax highlighting. Comma-separated strings from a list is probably that idiomatic in Python, especially if the ".join(" portion doesn't appear in the string literal color, and it's a common thing to only want for a message anyway.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds