5 ms·
It desugars similarly, but the Python version doesn't have a name. Any t-string is a t-string, there's no HTML t-string or SQL t-string or anything like that. I
by Timon3 1y ago
It desugars similarly, but the Python version doesn't have a name. Any t-string is a t-string, there's no HTML t-string or SQL t-string or anything like that. It's just a t-string you can pass to a function:
html_string = t"<something />"
sql_string = t"SELECT * FROM something"
In JS, the string has a prefix that can differ between languages, e.g.:
const htmlString = html`<something />`
const sqlString = sql`SELECT * FROM something`
and so on. See the difference?
- masklinn 1y agoExcept your labels are incorrect because neither `html_string` nor `sql_string` are strings, they're both Template objects, and the sink function is the one which processes it. No processing has happened to them by the end of the snippet, beyond creating the template object itself.
- Timon3 1y agoSure, choose different variable names, who cares. The essential difference is that the language is referenced at the declaration site, not the usage site, which makes the syntax highlighting far easier. Please engage with my point instead of criticizing trivialities.
- masklinn 1y ago> Please engage with my point instead of criticizing trivialities. Your complete misunderstanding of what's happening is not a triviality. > The essential difference is that the language is referenced at the declaration site, not the usage site, which makes the syntax highlighting far easier. Javascript has no built-in template tags beyond `String.raw`. If tooling has the capabilities to infer embedded language from arbitrary third party libraries, I would hope they have the ability to do utterly trivial flow analysis and realise that html(t"<something />") means the template string is pretty likely to be HTML content.
- Timon3 1y agoCome on, you're just being rude for no good reason. A badly chosen variable name doesn't show a "complete misunderstanding". Yes, the variable should have been named `html_template` instead of `html_string` - how often do I have to acknowledge this before you accept it? And it's obviously more complex to do syntax highlighting when the declaration site and usage site are possibly split apart by variable assignments etc. Yes, in the case you showed syntax highlighting is easy, but what if the `html` function takes more parameters, doesn't take the template as the first parameter, etc? There's a lot of possible complexity that tagged template literals don't have. Thus they are easier to do highlighting for. This is objectively true.
- conartist6 1y agoTagged template literals in JS have all that complexity. All of it. That tools you trust lie and pretend that's not the case doesn't make the language spec say anything different
- Timon3 1y agoNo, they literally don't, because they don't support these features! You can't split apart the declaration of the template literal and the "tagging". The tag is always part of the declaration, which it doesn't have to be in Python, as I've showed. You can't pass additional parameters to the tag function, it's always just the template & values. In Python, you can pass as many parameters as you want to the usage site, e.g. some_value = html(True, t"<something />", 42)
- conartist6 1y agoIt just sounds like you don't know JS very well, because in JS you can definitely split apart the declaration and the tag with ease. The thing implementing the tag is just a function after all: https://jsfiddle.net/rd2f1kot/ https://jsfiddle.net/rd2f1kot/
- 1y ago
- conartist6 1y agoJS references the language at the usage site, exactly like Python. There is no difference here in how the two languages behave.
- Timon3 1y agoNo, it doesn't, it references the language at the declaration site, because the declaration site always is the usage site. You can't split them apart. You can split them apart in Python - see the example in my first comment.