5 ms·
Sure, choose different variable names, who cares. The essential difference is that the language is referenced at the declaration site, not the usage site, which
by Timon3 1y ago
Sure, 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/
- Timon3 1y agoSorry, but do just not want to understand what I'm talking about? Your example doesn't show what you're saying it does. In Python you can do this: bar = "hello world" template = t"<something foo={bar} />" string = html(template) This is simply not possible in JS, because the template literal always must have the tag attached. You can't split them apart. If you try: const bar = "hello world" const template = `<something foo=${bar} />` you already have a string in the `template` variable. There's no access to the individual values anymore. It's already done. It's a string. No template. You can't pull apart the literal declaration and the tagging. Are we now done with this ridiculous game of deliberate misunderstandings?
- conartist6 1y agoI just don't see the same thing as you. This is what you say is simply not possible: let passthrough = (...args) => args; let bar = "hello world"; let template = passthrough`<something foo=${bar} />`; string = html(...template);
- conartist6 1y agoYes. It's a weak heuristic, but it's EXACTLY the same weak heuristic that JS is applying! IN other words, since custom template tags in JS *are literally just function calls* when a JS environment syntax highlights the code as HTML it's doing so based on an extremely weak heuristic (the identifier for the interpolation function is named "html"). Both Python and JS have the same problem.
- svieira 1y agoI think his point would be clearer if we focused on typing the usages statically. Consider `html(this_is_a_sql_template)` vs. `html"SELECT * FROM ..."` or `thing_that_consumes_html_template_type(oops_a_sql_template_type)`.
- 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.