Hacker News new | past | comments | ask | show | jobs | submit login

So, the f-string in Python is "spelled" that way because another leading character was the only ASCII syntax left for such a thing. It's odd that PRQL and now potentially C++ might copy it. In the PRQL case it was a new thing so they could have chosen anything, double quotes (like shell interpolation) or even backticks, that seem to make more sense.

Also the f- prefix was supposed to be short for format and pronounced that way. But "eff" caught on and now devs the world over are calling them "eff strings" ... funny. :-D






PRQL contributor here:

That is a valid point and something I've also been thinking about lately. I can't speak for the others but in my case the Python string interpolation syntax was the one I was most familiar with, other than bash, so it was just the default. The big idea really is to have string interpolation and the syntax is somewhat secondary but we do aim for ergonomics with PRQL so it is a consideration.

Since then I've seen more alternatives like `Hello ${var}!` in JS/TS and $"Hello {var}!" in F#. Not sure that there's a clear way to prefer one approach over the others.

What would you consider to be factors that would make you prefer one over the others?


I suppose simplicity and familiarity would be the primary two goals. Then congruence with SQL would be another factor specifically for PRQL.

some factors:

ease of typing: so regular quotes are better vs backticks (even with a prefix), F-prefix - better than $, requiring Shift

ease of learning: here letter-mnemonic seems easiest: so I-prefix for "interpolation" or E-prefix for "expression" or maybe V-prefix for "variable". Or maybe F for "formatted" is also fine?

familiarity: so F-prefix due to Python?


Why is it odd to copy a popular and fitting alternative? What's the better one?

Because it’s an variant with a wart, only picked from being backed into a corner. I mentioned shell interpolation in my previous comment.

We could introduce g-strings instead.

> [...] another leading character was the only ASCII syntax left for such a thing.

Not really? The original PEP [1] for example considered `i"asdf"` as an alternative syntax. Any ASCII Latin letter besides from `b`, `r` and `u` would have been usable.

[1] https://peps.python.org/pep-0498/#how-to-denote-f-strings


As an alternative to another leading ascii character, you offer another leading ascii character?

Why is this reply to someone who misunderstood downvoted?



Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: