xmlCtx = MkXmlCtx()
SetNsPfx(xmlCtx, "foo", "http://foo.com/ns")
OpenTag(xmlCtx, "foo:bar")
SetAttr(xmlCtx, "name", "value")
Write(xmlCtx, "string")
CloseTag(xmlCtx)
xml = GetXml(xmlCtx)
It may look boring but it's exactly the right thing. Syntactic sugar is deceptive. A declarative approach is not the right pattern in JS. (It's essential to XML, but XML is a very different thing.)What if we'd had better HTML-in-JS syntax all along?
141–150 of 170 posts
Re: What if we'd had better HTML-in-JS syntax all along?
#142Earlier quoted context omitted.
> It may be interesting to recall that initially the only way to output HTML was by `document.write()` using strings (which was pretty declarative). I think people also forget how slow a lot of JS was really until V8. I remember having server code generate JS arrays (creating them from an xhr request was too slow), that in turn would document.write (manipulating the DOM was also super slow) data on the client to make…
It wasn't just JS, you could actually watch JPEG images becoming decoded, esp. on a computer which wasn't exactly new. Layout of complex markup could take seconds, reflowing and repainting was out of question. JS as an interpreteded language was accordingly much slower than native code. There was no way to do fast, declarative HTML in JS – and not much of a use case for this. (For much the same reasons, there was no…
I even used to disable images and just selectively download them.
Re: What if we'd had better HTML-in-JS syntax all along?
#143> I have a theory that a grave mistake was made in 1995 - the decision not to have a neat, succinct and declarative way of representing html elements in javascript. It may be interesting to recall that initially the only way to output HTML was by `document.write()` using strings (which was pretty declarative). The genuine way of generating HTML in JS were various methods of `String.prototype` for generating HTML form…
There was also the the idea that JavaScript was just one way of scripting the page. VisualBasic Script (VBScript) had momentum in IE releases. The general idea was that the user-agent was going to be able to parse multiple scripting languages, the list of which would probably grow as time went on. Think native TypeScript parsing in a browser today!
The best way to take advantage of WebAssembly, since it is here anyway, is to abuse it to recover all plugins that were taken away.
Re: What if we'd had better HTML-in-JS syntax all along?
#144> I have a theory that a grave mistake was made in 1995 - the decision not to have a neat, succinct and declarative way of representing html elements in javascript. It may be interesting to recall that initially the only way to output HTML was by `document.write()` using strings (which was pretty declarative). The genuine way of generating HTML in JS were various methods of `String.prototype` for generating HTML form…
There was also the the idea that JavaScript was just one way of scripting the page. VisualBasic Script (VBScript) had momentum in IE releases. The general idea was that the user-agent was going to be able to parse multiple scripting languages, the list of which would probably grow as time went on. Think native TypeScript parsing in a browser today!
Re: What if we'd had better HTML-in-JS syntax all along?
#145Earlier quoted context omitted.
I have been using JS since the mid 90s, but I don't recall needing arrays or objects back then. Frankly we weren't trying to build applications and any real programming work was done on the back end (remember that xmlHttpRequest wouldn't exist for years to come, so any changes to the page were made by going to a new page which would require a round trip to the server, so the server could do anything it needed to do t…
The other major uses of JavaScript were hover-over-button effects, and scrolling text in the status bar
Re: What if we'd had better HTML-in-JS syntax all along?
#146QML is this and more.
Re: What if we'd had better HTML-in-JS syntax all along?
#147> I have a theory that a grave mistake was made in 1995 - the decision not to have a neat, succinct and declarative way of representing html elements in javascript. It may be interesting to recall that initially the only way to output HTML was by `document.write()` using strings (which was pretty declarative). The genuine way of generating HTML in JS were various methods of `String.prototype` for generating HTML form…
But they are the wrong abstraction for building DOM nodes. They're error prone (no guarantees of correctness) , encoding woes) and are write only (how do you modify a node that is encoded in a string). And what do expressions like html.substr(0, 7) even mean?
First class HTML composition in JS is pretty dang important.
Re: What if we'd had better HTML-in-JS syntax all along?
#148I have a hypothesis about a different way to organize responsibilities within webpages. I think the split of "content" to HTML and "presentation" to CSS was a mistake. To me, those are both describing content. That is, the author's intent to emphasize a particular part of text, whether via tags or CSS, is part of the content. I think there was a missed opportunity to instead split page layout into its own technology.…
Re: What if we'd had better HTML-in-JS syntax all along?
#149Earlier quoted context omitted.
The creators of JSX (Facebook employees obviously) once said in a talk that their biggest inspiration for JSX was server-side PHP code which supports being interspersed with HTML.
Link? You might be misremembering Pete Hunt's talk about React's design decisions: https://www.youtube.com/watch?v=x7cQ3mrcKaY where he makes the case against the "separation of concerns" cargo cult.
However, if you check out the History section [0] on Wikipedia you will see this confirmed:
> React was created by Jordan Walke, a software engineer at Facebook, who released an early prototype of React called "FaxJS". He was influenced by XHP, an HTML component library for PHP.
[0]: https://en.wikipedia.org/wiki/React_(web_framework)#History
Re: What if we'd had better HTML-in-JS syntax all along?
#150Earlier quoted context omitted.
Javascript already has the ability to define new abstractions. They're called functions. Imagine you want a new "tag" for defining a Widget. Make yourself a Widget function which takes some arguments, maybe the name of the widget, the mass, and the price. Those arguments can themselves be HTML, created either using E4X or any other means you like. This lets you compose things together. For example, perhaps the price…
Sure, but the why are we talking about special syntax in the first place? In any non-trivial projects you're rarely going to be working with primitive tags, it's always higher level components.