Re:PEP 750 – Template Strings (t-strings) have been accepted
by zahlman on Thursday April 10, 2025 @10:23PM
(#43649907)
As far as I can tell from the linked proposal, it wouldn't have involved such evaluation either. It seems like it was intended to work fundamentally the same way as it currently does in Python: by analyzing the string literal ahead of time and translating into equivalent explicit formatting code, as syntactic sugar. There seem to have been many misunderstandings in the GitHub discussion.
[ Parent
| on HN ]
Re:PEP 750 – Template Strings (t-strings) have been accepted
by mjevans on Thursday April 10, 2025 @11:00PM
(#43650096)
In that case, I might have misunderstood the intent of those examples.
However the difficulty of understanding also illustrates the increased maintenance burden and language complexity.
Re:PEP 750 – Template Strings (t-strings) have been accepted
by eviks on Friday April 11, 2025 @02:26AM
(#43651032)
Unless workarounds to a missing feature have a higher maintenance burden like in this case, and you can't avoid it via learning
Re:PEP 750 – Template Strings (t-strings) have been accepted
by mjevans on Friday April 11, 2025 @05:39AM
(#43652101)
Go's preferred way would probably be something like compute the aliased operations on the line(s) before, then reference the final values.
E.G. Adapting https://github.com/golang/go/issues/34174
f := 123.45
fmt.Fprintln("value=%08.3f{f}") // value=0123.450
fmt.Fprintln("value=%08.3f", f) // value=0123.450
s := "value"
fmt.Fprintln("value='%50s{s}'") // value='<45 spaces>value'
fmt.Fprintln("value='%50s'", s) // value='<45 spaces>value'
The inline {variable} reference suffix format would be less confusing for situations that involve _many_ variables. Though I'm a bit more partial to this syntax with an immediately trailing %{variable} packet since my gut feeling is that special case would be cleaner in a parser. fmt.Fprintln("value=%08.3f%{f}") // value=0123.450
fmt.Fprintln("value='%50s%{s}'") // value='<45 spaces>value'