←back to thread

620 points tambourine_man | 3 comments | | HN request time: 0.439s | source
Show context
florbnit ◴[] No.43754419[source]
> In addition, I hope that the tooling ecosystem will adapt to support t-strings. For instance, I’d love to see black and ruff format t-string contents, and vscode color those contents, if they’re a common type like HTML or SQL.

This is such a strange take on t-strings. The only way for anything to infer that the template string is supposed to turn into valid HTML or SQL is to base it of the apparent syntax in the string, which can only be done in an ad-hoc fashion and has nothing to do with the template string feature.

The way the feature has been designed there is no indication in the string itself what type of content it is or what it will eventually be converted to. It’s all handled by the converting function.

As others have added, something like sql”select * from {table}” would have been able to do this, but there’s not even any guarantees that something that is in a template that will be converted into valid sql by a converting function should be any type of valid sql prior to that conversion. For all you know t“give me {table} but only {columns}” might be a converted into valid sql after the template is processed.

replies(7): >>43754586 #>>43754693 #>>43754745 #>>43754827 #>>43755016 #>>43755210 #>>43757519 #
1. spankalee ◴[] No.43755016[source]
I think you'll just see a pattern like:

    html(t"<h1>Hello</h1>")
And highlighters and static analyzers will key off of this.

JavaScript's tagged template literals are actually about as flexible as this, since you can dynamically choose the tag function, it's just very rare to do so, so tools assume a lot based on the name of the function. Python tools can basically do the same thing, and just not support t-strings that aren't nested inside a well-named processing function.

replies(2): >>43756746 #>>43802380 #
2. dandellion ◴[] No.43756746[source]
Another option would be type hints, something like `title: HTMLTemplate = t"<h1>Hello</h1>"`.
3. florbnit ◴[] No.43802380[source]
> And highlighters and static analyzers will key off of this.

Then the t is redundant and we don’t need t strings involved in any way. This would work just as well. In fact better by using html("<h1>Hello</h1>") and have it return a html object instead of returning a just a string which is what t-strings will do. So literally the only contribution from t-strings in that context is to make things worse.

If they had just standardized some way of putting semantics into the template everything would be better. Let us define a “sql = temlate(….)” and use sql”…”