3 ms·
My feeling is that if html and js had syntactically shared data structures at their conception, we wouldn't have quite so much frontend mess as we do now and de
by leontrolski 7y ago
My feeling is that if html and js had syntactically shared data structures at their conception, we wouldn't have quite so much frontend mess as we do now and declarative UI would have been the norm for a while. Having said that, I'm not sure how much precedent this has in UI frameworks outside of the web.
- k__ 7y agoYou think so? What would be different if Document.createElement('a') Would look like <a/> ? The rest would still be imperative code.
- capableweb 7y agoThe first one is imperative and locks the implementation to use the Document object and the createElement function. The second one is declarative and leaves it up to the receiver to handle however they seem fit. I'm not arguing one is better or worse, or that we would be better off if we we're using the JSX way with native support in the browsers, just explaining how I see the differences between the two.
- colejohnson66 7y agoIt’s been a bit since I’ve used JS (so I may have the latter syntax wrong), but I’d prefer the JSX style of var elem = <a href="#test">Test</a>; over var elem = document.createElement("a"); elem.href = "#test"; elem.innerText = "Test"; jQuery allows one to do something similar to JSX (which is nice): var elem = $("<a href='#test'>Test</a>");
- ken 7y agoI don't interpret "html and js had syntactically shared data structures" to mean what you wrote, unless you also replace all other JS data structures (arrays and dicts and ...) with <> syntax. You've made it more concise but it's still distinct. For an example of a system where the programming language and document generator share data structures, look at Hiccup (and Reagent). One of their very first examples is putting a loop inside a list. There's no special API for the attributes -- it's just an ordinary map. There's no special API for the children -- it's just an ordinary vector.