4 ms·
What other languages have this feature? I'm not aware of any
by nu11ptr 1y ago
What other languages have this feature? I'm not aware of any
- martinky24 1y agoThey literally discuss this in the article.
- pansa2 1y ago> [T-strings] are the pythonic parallel to JavaScript’s tagged templates.
- hocuspocus 1y agoScala since 2014. Java 22 had the feature as preview but it was removed in 23, it'll come back after some refinement.
- thatnerdyguy 1y agoC# has InterpolatedStringHandler which isn't quite the same thing, but (in my understanding), trying to address the same core issues.
- WorldMaker 1y agoC# InterpolatedString is very close, with the twisty bit being that C# can rely on static typing for safety so the "f-string" and "t-string" variants use the same literal syntax and depend on what function they are passed to, whereas in both Python and Javascript they have different literal syntaxes. Python chose to use a different literal prefix to its literals ("f" versus "t") and Javascript chose to use a function-call syntax as prefix (`templateString` versus html`templateString` where html is a function in scope).
- neonsunset 1y agoFor the case like here it’s closer to FormattableString that’s what EF Core’s composable FromSql method works on top of. Both address custom interpolation but from different angles / for different scenarios.
- jerf 1y agoMany languages have similar features. For instance, Python has the % operator that is a template format that allows interpolating values based on a template string with a variety of printf-like features: https://python-reference.readthedocs.io/en/latest/docs/str/formatting.html https://python-reference.readthedocs.io/en/latest/docs/str/f... Also, Python has the .format method on strings, which is a template format that allows interpolating values based on a template string: https://www.geeksforgeeks.org/python-string-format-method/ https://www.geeksforgeeks.org/python-string-format-method/ As another example, Python has f-strings that are a template format that allows interpolating values based on a template string: https://www.geeksforgeeks.org/formatted-string-literals-f-strings-python/ https://www.geeksforgeeks.org/formatted-string-literals-f-st... Also, you can also find languages like Python that have a rich ecosystem of third party templating solutions. These are often intended for things like rendering entire web pages but many of them have relatively simple ways of using their templating functionality in a fairly reasonable amount of code, if you just want to have a template format that allows interpolating values based on a template string. So, as you can see, many other languages have this feature, as you can tell from all the examples I have shown you here. (To spell it out for those who may find this too subtle... somehow... I'm not a fan of this simply because Python has gone from "There should be one-- and preferably only one --obvious way to do it." to "there's half-a-dozen ways to do it and if they are all wrong Python 3.x+1 will introduce a seventh" and I'm just not seeing the benefits worth the tradeoffs here.)
- viccis 1y agoWhat would you say is the alternative?
- jerf 1y agoIf I were in charge of Python, I'd probably feature-freeze it. It is already too large, but shrinking it is impractical. Failing that, because it probably would fail, I would be raising the bar sky-high on new feature additions. It seems like the project has actually lowered the bar in the last few versions. What was once one of my favorite languages, if not my favorite, is now a language I try to avoid, and approaching one I actively recommend against. When I'm writing it myself it's ok, but using other people's code in it is getting harder and harder, as they keep using all the features.